/* FIELD COMMS: an intentionally local mock, layered over the existing game HUD (js/ui-chat.js).
   Restyled 2026-10-09 (direction A "Field Terminal", Proposed): the launcher and the side panel are HUD plates
   (base.css ::before, --c1/--c2 cuts, --bd, --fill, --deco); text in IBM Plex Sans Thai, labels in Chakra Petch,
   counts and times in Oxanium; channel colours stay per channel (--channel from ui-chat.js). Only the input takes
   text selection; the log scrolls inside the panel (contained, thin bar). No backdrop blur over the live canvas. */
#chatLauncher,
#chatMini,
#chatPanel {
  font-family: var(--f-body);
}
#chatLauncher {
  --c1: 8px;
  --c2: 8px;
  --deco: linear-gradient(var(--accent), var(--accent)) 0 8px / 2px calc(100% - 16px) no-repeat;
  position: absolute;
  top: calc(156px + var(--st));
  left: calc(24px + var(--sl));
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 7px 12px;
  text-align: left;
}
#chatLauncher > .icon {
  width: 22px;
  height: 22px;
  color: var(--accent);
}
#chatLauncher > span {
  font: 600 14px/1.1 var(--f-head);
}
#chatLauncher small {
  display: block;
  color: var(--dim);
  font: 600 11px/1 var(--f-head);
  letter-spacing: 0.14em;
  margin-top: 2px;
}
#chatLauncher kbd {
  margin-left: 12px;
}
.chat-count {
  display: inline-grid;
  place-items: center;
  border-radius: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 11px/1 var(--f-num);
  min-width: 18px;
  height: 17px;
  padding: 0 4px;
  -webkit-clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
}

/* ------------------------------------------------------------------------------------------------- mini feed */
#chatMini {
  position: absolute;
  bottom: calc(153px + var(--sb));
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 48px));
  padding: 9px 13px 10px;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(var(--line-strong), var(--line-strong)) 0 0 / 1px 100% no-repeat,
    linear-gradient(90deg, rgba(9, 14, 15, 0.62), rgba(9, 14, 15, 0.28) 70%, rgba(9, 14, 15, 0));
  color: var(--text);
  text-align: left;
  box-shadow: none;
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
}
.chat-mini-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 19px;
  margin-bottom: 4px;
  color: var(--dim);
}
.chat-mini-heading > .icon {
  width: 14px;
  height: 14px;
  color: var(--accent);
}
.chat-mini-heading b {
  font: 600 13px/1 var(--f-head);
}
.chat-mock {
  display: inline-block;
  font: 600 11px/1 var(--f-head);
  letter-spacing: 0.08em;
  color: var(--info);
  border: 1px solid var(--info-dim);
  padding: 2px 5px;
  border-radius: 0;
  vertical-align: middle;
  text-shadow: none;
}
.chat-mini-expand {
  margin-left: auto;
}
.chat-mini-expand .icon {
  width: 13px;
  height: 13px;
  color: var(--dim);
}
#chatMiniLines {
  display: grid;
  gap: 2px;
}
.chat-mini-line {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 13px;
  line-height: 1.55;
}
.chat-mini-line b {
  color: var(--channel);
  font: 600 12px/1 var(--f-head);
}
.chat-mini-line strong {
  font-weight: 600;
  color: var(--text);
}

/* ------------------------------------------------------------------------------------------------- side panel */
#chatPanel {
  --chat-font-size: 15px;
  --c1: 16px;
  --c2: 16px;
  --bd: rgba(88, 112, 118, 0.85);
  --deco: linear-gradient(var(--accent), var(--accent)) 16px 0 / 88px 2px no-repeat;
  --fill: var(--grid-faint, linear-gradient(transparent, transparent)), linear-gradient(180deg, #1a2427, #101719 40%);
  position: absolute;
  top: calc(var(--chat-view-top, 0px) + 16px + var(--st));
  left: calc(16px + var(--sl));
  width: min(458px, calc(100vw - 32px - var(--sl) - var(--sr)));
  height: calc(var(--chat-view-height, 100dvh) - 32px - var(--st) - var(--sb));
  display: flex;
  flex-direction: column;
  z-index: 12;
  color: var(--text);
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: 12px 0 40px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  animation: chat-enter 0.16s ease-out;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex: 0 0 auto;
  padding: 14px 14px 12px 20px;
  border-bottom: 1px solid var(--line);
  background:
    var(--hazard-dim) 20px 100% / 72px 3px no-repeat,
    linear-gradient(90deg, rgba(255, 178, 30, 0.08), transparent 60%);
  gap: 10px;
}
.chat-eyebrow {
  font: 600 12px/1 var(--f-head);
  letter-spacing: 0.16em;
  color: var(--dim);
}
.chat-eyebrow i {
  font-style: normal;
  color: var(--faint);
  padding: 0 5px;
}
.chat-header h2 {
  margin: 6px 0 0;
  font: 700 22px/1.25 var(--f-head);
  letter-spacing: 0;
}
/* live chat (stage 1): the MOCK chip becomes the link state */
.chat-mock[data-state="online"] { color: #0c1214; background: var(--good, #7fe08a); border-color: transparent; }
.chat-mock[data-state="connecting"] { color: #0c1214; background: var(--accent, #ffb21e); border-color: transparent; }
.chat-mock[data-state="offline"] { color: var(--text, #e8ede6); background: rgba(150, 160, 165, 0.35); border-color: transparent; }
.chat-header h2 .chat-mock {
  margin-left: 7px;
}
.chat-header-actions {
  display: flex;
  gap: 4px;
}
.chat-header button {
  border: 1px solid var(--line-strong);
  background: rgba(9, 14, 15, 0.6);
  border-radius: 0;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  font: 700 13px/1 var(--f-head);
  color: var(--text);
  -webkit-clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
  clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.chat-header button.is-pressed {
  border-color: var(--accent);
  color: var(--accent);
}
.chat-header #chatClose {
  margin-left: 6px;
  border-color: var(--accent-dim);
  color: var(--accent);
}
.chat-header button:disabled {
  opacity: 0.3;
}
.chat-header .icon {
  width: 20px;
  height: 20px;
}
.chat-workspace {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  min-height: 0;
  flex: 1;
}
.chat-channels {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  padding: 8px 6px;
  border-right: 1px solid var(--line);
  background: rgba(4, 8, 9, 0.35);
  scrollbar-width: none;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.chat-channels::-webkit-scrollbar {
  display: none;
}
.chat-channels button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 62px;
  flex-shrink: 0;
  padding: 6px 0;
  border: 1px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--dim);
  font: 600 12px/1.1 var(--f-head);
}
.chat-channels .icon {
  width: 22px;
  height: 22px;
  color: var(--channel);
  opacity: 0.7;
}
.chat-channels button[aria-pressed="true"] {
  color: var(--text);
  background: linear-gradient(90deg, color-mix(in srgb, var(--channel) 18%, transparent), transparent);
  border-color: color-mix(in srgb, var(--channel) 35%, transparent);
}
.chat-channels button[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  background: var(--channel);
}
.chat-channels button[aria-pressed="true"] .icon {
  opacity: 1;
}
.chat-channels .chat-count {
  position: absolute;
  top: 3px;
  right: 0;
}
.chat-conversation {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.chat-channel-heading {
  display: grid;
  gap: 3px;
  flex-shrink: 0;
  padding: 14px 16px 10px;
}
.chat-channel-heading b {
  font: 700 16px/1.25 var(--f-head);
}
.chat-channel-heading > span {
  font-size: 13px;
  color: var(--dim);
  line-height: 1.5;
}
.chat-preview-note {
  padding: 6px 16px;
  font-size: 13px;
  color: var(--info);
  border-block: 1px solid var(--line);
  background: var(--info-a10);
}
.chat-log-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
#chatLog {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 16px 12px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  touch-action: pan-y;
  overflow-anchor: none;
}
#chatLog::-webkit-scrollbar {
  width: 6px;
}
#chatLog::-webkit-scrollbar-thumb {
  background: var(--line-strong);
}
.chat-history-label {
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  padding: 8px 0;
}
.chat-history-label span {
  color: var(--faint);
  margin-left: 8px;
}
.chat-message {
  padding: 9px 0 10px;
  border-bottom: 1px solid var(--line-a60);
  font-size: var(--chat-font-size);
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.chat-message-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: max(12px, 0.8em);
  line-height: 1.5;
}
.chat-message-channel {
  color: var(--channel);
  background: color-mix(in srgb, var(--channel) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--channel) 28%, transparent);
  border-radius: 0;
  font: 600 max(11px, 0.9em) / 1.4 var(--f-head);
  padding: 0 5px;
}
.chat-message-meta b {
  color: var(--text);
  font-weight: 600;
}
.chat-message-meta time {
  margin-left: auto;
  font: 500 11px/1 var(--f-num);
  color: var(--faint);
}
.chat-message p {
  margin: 4px 0 0;
}
.chat-message.notice {
  padding: 10px;
  margin: 8px -5px;
  border: 1px solid rgba(255, 122, 107, 0.25);
  border-left: 3px solid var(--bad);
  background: rgba(255, 122, 107, 0.05);
  color: #f2c9bf;
}
.chat-message.mention {
  background: linear-gradient(90deg, var(--accent-a08), transparent);
}
.chat-message.own .chat-message-meta b {
  color: var(--good);
}
.chat-item {
  color: var(--accent);
}
.chat-message mark {
  color: var(--accent);
  background: var(--accent-a16);
  border-radius: 0;
  padding: 0 3px;
}
.chat-local {
  color: var(--dim);
  font-size: 11px;
}
#chatLatest {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-ink);
  font: 700 13px/1 var(--f-head);
  min-height: 36px;
  padding: 6px 16px;
  border: 0;
  border-radius: 0;
  white-space: nowrap;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
  -webkit-clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
  clip-path: polygon(7px 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%, 0 7px);
}

/* ------------------------------------------------------------------------------------------------- composer */
#chatComposer {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: rgba(4, 8, 9, 0.5);
  padding: 10px 12px 9px;
}
.chat-compose-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 7px;
  font-size: 13px;
  color: var(--dim);
}
/* a game-styled picker: no native arrow, chamfered, channel colour */
#chatDestination {
  -webkit-appearance: none;
  appearance: none;
  color: var(--channel, var(--text));
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%2395a39e' stroke-width='1.8'/%3E%3C/svg%3E") right 10px top 50% / 11px 7px no-repeat,
    var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 0;
  font: 600 14px/1.2 var(--f-head);
  min-height: 32px;
  padding: 4px 28px 4px 10px;
  cursor: default;
}
#chatCount {
  margin-left: auto;
  font: 500 12px/1 var(--f-num);
}
.chat-compose-row {
  display: flex;
  gap: 7px;
}
#chatInput {
  min-width: 0;
  width: 100%;
  height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: rgba(4, 8, 9, 0.75);
  color: var(--text);
  font: 15px/1.3 var(--f-body);
  padding: 10px 12px;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
#chatInput:focus {
  outline: none;
  border-color: var(--info);
  box-shadow: inset 0 0 0 1px var(--info-dim);
}
#chatInput::placeholder {
  color: var(--faint);
}
#chatSend {
  display: grid;
  place-items: center;
  width: 48px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 0;
  border: 0;
  color: var(--accent-ink);
  background: var(--accent);
  -webkit-clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}
#chatSend .icon {
  width: 22px;
  height: 22px;
}
#chatSend:disabled {
  background: var(--panel-3);
  color: var(--faint);
}
#chatDraftHint {
  display: block;
  color: var(--dim);
  font-size: 12px;
  margin-top: 7px;
}
#chatReadOnly {
  display: flex;
  gap: 10px;
  align-items: center;
  background: rgba(4, 8, 9, 0.5);
  border-top: 1px solid var(--line);
  padding: 16px 18px;
  color: var(--dim);
  font-size: 14px;
}
#chatReadOnly > .icon {
  width: 21px;
  height: 21px;
  color: var(--accent);
}
#chatToWorld {
  display: block;
  min-height: 36px;
  background: none;
  border: 0;
  padding: 8px 0 0;
  font: 600 14px/1.2 var(--f-head);
  color: var(--info);
}
.chat-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 14px 9px;
  background: rgba(4, 8, 9, 0.55);
  color: var(--dim);
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.chat-footer span:last-child {
  color: var(--accent);
}
.chat-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
body.chat-open #chatLauncher {
  visibility: hidden;
}

/* ------------------------------------------------------------------------------------------------- placement */
body:not(.touch) #toasts {
  top: calc(214px + var(--st));
}
body:not(.touch) #svc {
  bottom: calc(285px + var(--sb));
}
body.touch #chatLauncher {
  top: calc(190px + var(--st));
  left: calc(14px + var(--sl));
  min-height: 44px;
  padding: 5px 10px;
}
body.touch #chatMini {
  width: clamp(260px, 40vw, 420px);
  left: 44%;
  bottom: calc(112px + var(--sb));
  padding: 7px 10px;
}
body.touch #chatMini .chat-mini-line {
  font-size: 12px;
}
body.touch #chatPanel {
  width: min(450px, 55vw);
}
body.touch .chat-header button {
  width: 44px;
  height: 44px;
}
body.touch .chat-header {
  padding: 10px 12px 10px 16px;
}
body.touch .chat-header h2 {
  font-size: 19px;
}
body.touch #chatInput {
  font-size: 16px;
  height: 44px;
}
body.touch #chatSend {
  height: 44px;
}
body.touch #chatDestination {
  min-height: 44px;
  font-size: 16px;
}
body.touch #chatToWorld {
  min-height: 44px;
}
body.touch #toasts {
  top: calc(240px + var(--st));
}
body.touch #svc {
  bottom: calc(238px + var(--sb));
}
@media (max-height: 500px) and (orientation: landscape) {
  body.touch #chatLauncher {
    top: calc(186px + var(--st));
  }
  body.touch #chatMini {
    left: 43%;
    width: clamp(244px, 36vw, 355px);
    bottom: calc(97px + var(--sb));
    padding: 5px 9px;
  }
  body.touch #chatMini .chat-mini-line {
    font-size: 12px;
    line-height: 1.5;
  }
  body.touch #chatMini .chat-mini-line b {
    font-size: 11px;
  }
  #chatPanel,
  body.touch #chatPanel {
    --c1: 0px;
    --c2: 14px;
    top: calc(var(--chat-view-top, 0px) + var(--st));
    left: var(--sl);
    width: min(440px, 58vw);
    height: calc(var(--chat-view-height, 100dvh) - var(--st) - var(--sb));
  }
  .chat-header {
    padding: 4px 8px 4px 12px !important;
  }
  .chat-eyebrow {
    display: none;
  }
  .chat-header h2 {
    margin: 0;
    font-size: 17px;
  }
  .chat-workspace {
    grid-template-columns: 62px minmax(0, 1fr);
  }
  .chat-channels {
    gap: 2px;
    padding: 3px;
  }
  .chat-channels button {
    min-height: 48px;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3px;
    font-size: 11px;
  }
  .chat-channels .icon {
    width: 18px;
    height: 18px;
  }
  .chat-channels button span {
    width: 100%;
    line-height: 1;
  }
  .chat-channel-heading {
    padding: 6px 11px;
  }
  .chat-channel-heading b {
    font-size: 14px;
  }
  .chat-channel-heading > span {
    display: none;
  }
  .chat-preview-note {
    padding: 4px 11px;
    font-size: 12px;
  }
  #chatLog {
    padding: 4px 11px;
  }
  .chat-message {
    padding: 7px 0;
  }
  #chatComposer {
    padding: 5px 8px 6px;
  }
  .chat-compose-meta {
    padding-bottom: 4px;
  }
  #chatDraftHint,
  .chat-footer {
    display: none;
  }
  body.touch #toasts {
    top: 238px;
    max-width: 170px;
  }
}
@media (max-width: 700px) and (orientation: portrait) {
  #chatMini,
  body.touch #chatMini {
    width: calc(100vw - 32px);
    left: 50%;
    bottom: calc(324px + var(--sb));
  }
  #chatPanel,
  body.touch #chatPanel {
    --c1: 0px;
    --c2: 0px;
    width: calc(100vw - var(--sl) - var(--sr));
    left: var(--sl);
    top: calc(var(--chat-view-top, 0px) + var(--st));
    height: calc(var(--chat-view-height, 100dvh) - var(--st) - var(--sb));
  }
  body.touch #chatLauncher {
    top: calc(188px + var(--st));
    left: calc(12px + var(--sl));
  }
  body:not(.touch) #chatLauncher {
    top: 268px;
  }
  body:not(.touch) #toasts {
    top: 321px;
  }
  body.touch #toasts {
    top: 253px;
  }
  body.touch #svc,
  body:not(.touch) #svc {
    bottom: calc(434px + var(--sb));
  }
}
@media (prefers-reduced-motion: reduce) {
  #chatPanel {
    animation: none;
  }
}
@keyframes chat-enter {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
