/* comms — pictochat prototype
   lightweight, practical. small radii, system fonts, no blur, no decorative animation. */

:root {
  /* dark neutral greys — Discord-adjacent but flatter and slightly warmer */
  --bg-deep:    #161616;   /* page bg */
  --bg-card:    #1f1f20;   /* message log bg */

  --surface-1:  #28282a;   /* app shell */
  --surface-2:  #1c1c1d;   /* compose card */
  --surface-3:  #38383a;   /* button base */
  --surface-3h: #45454a;   /* button hover */
  --surface-3d: #2c2c2e;   /* button pressed */
  --inset-bg:   #18181a;   /* inset wells */

  --border:     rgba(255, 255, 255, 0.06);
  --border-2:   rgba(255, 255, 255, 0.12);

  --text:       #e8e8ea;
  --text-mute:  #8a8a90;

  --mint:       #6ee7d3;   /* accent — kept for character */
  --peach:      #ffb088;   /* accent — kept for character */

  --top-sheen:  rgba(255, 255, 255, 0.18);
  --bot-shadow: rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;          /* lock the page itself; only the message log scrolls */
  overscroll-behavior: none; /* no rubber-band on the body */
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 500;
  color: var(--text);
  background: var(--bg-deep);
}

/* ---------- main app shell ---------- */
.comms-app {
  width: calc(100% - 32px);
  max-width: 640px;
  height: calc(100vh - 32px);
  height: calc(100dvh - 32px); /* dvh adapts when mobile URL bar / keyboard shows */
  margin: 16px auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-2);
  border-radius: 4px;
}

/* ---------- mobile / small viewport ---------- */
@media (max-width: 600px) {
  .comms-app {
    /* Pin the app to the visible viewport. iOS scrolls the visual viewport
       independently when the keyboard opens; --app-top mirrors
       window.visualViewport.offsetTop so the fixed app tracks the visible
       area instead of getting pushed off-screen. */
    position: fixed;
    top: var(--app-top, 0);
    left: 0;
    width: 100%;
    /* --app-h is window.visualViewport.height — shrinks when the keyboard
       slides up, so the message log absorbs the change via flex: 1. */
    height: var(--app-h, 100dvh);
    margin: 0;
    padding: 8px;
    border-radius: 0;
    border: none;
  }
  /* Belt-and-suspenders against iOS auto-zoom on input focus
     (maximum-scale=1 in the viewport meta is the primary defense). */
  #messageInput,
  .name-label input {
    font-size: 16px;
  }
}

/* ---------- shared input pill ---------- */
.name-label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--inset-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 4px 10px;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}
.name-label:focus-within {
  border-color: rgba(255, 255, 255, 0.18);
}
.name-label-text {
  font-size: 11px;
  color: var(--text-mute);
  font-weight: 600;
  letter-spacing: 0.3px;
}
.name-label input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  padding: 2px 0;
  min-width: 0;
}
.name-label input::placeholder {
  color: var(--text-mute);
  opacity: 0.55;
  font-weight: 500;
}
.header-name {
  flex: 0 1 auto;
  padding: 4px 10px;
}
#scrollBottomBtn {
  margin-left: auto;        /* push self + name pill to the right end */
}
.header-name .name-label-text { font-size: 11px; }
.header-name input { font-size: 12px; width: 100px; }

/* ---------- message log ---------- */
.message-log {
  flex: 1;
  min-height: 100px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow-y: auto;
  padding: 10px;
  margin-bottom: 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.18) transparent;
}
.message-log::-webkit-scrollbar { width: 6px; }
.message-log::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.18);
  border-radius: 1px;
}

.message {
  margin-bottom: 10px;
}
.message:last-child { margin-bottom: 2px; }

.message-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 11.5px;
}
.message-name {
  font-weight: 700;
  color: var(--mint);
  letter-spacing: 0.2px;
}
.message.me .message-name {
  color: var(--peach);
}
.message-time {
  color: var(--text-mute);
  font-size: 10px;
  opacity: 0.7;
}

.message-bubble {
  position: relative;
  background: #fafafa;
  border-radius: 0;
  overflow: hidden;
}
.message-text {
  color: #1a1a1a;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  font-weight: 500;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.message-strokes {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  display: block;
  pointer-events: none;
  image-rendering: pixelated;
}
.message-strokes.solo {
  position: relative;
}

/* play button — carved into the bottom-right of every message bubble,
   mirrors the send button in the compose area. clicking plays all
   subsequent messages flipnote-style inside this bubble. */
.message-play {
  position: absolute;
  bottom: 0;
  right: 0;
  background: var(--surface-3);
  color: var(--mint);
  border: 1px solid var(--border);
  border-right: none;
  border-bottom: none;
  border-radius: 0;
  /* Same proportions as the send button (16.67% × 33.33% of bubble).
     Whatever the sender's button covered, the play button covers too. */
  width:  calc(80 / 480 * 100%);
  height: calc(30 / 90  * 100%);
  padding: 0;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  z-index: 2;
  letter-spacing: 0.3px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.message-play:hover {
  background: var(--surface-3h);
}

/* ---------- compose card ---------- */
.compose {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 8px;
}

.paint-toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.tool-group {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--inset-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
}
.tool-btn {
  width: 28px;
  height: 28px;
  font-size: 14px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 700;
}
.tool-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.size-btn {
  width: 28px;
  height: 24px;
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 2px;
}
.size-btn span {
  display: block;
  background: var(--text);
  width: 16px;
  border-radius: 0;
}
.size-btn:hover {
  background: rgba(255,255,255,0.05);
}
.size-btn.active {
  background: var(--surface-3);
}

.palette {
  display: grid;
  grid-template-columns: repeat(8, 16px);
  grid-template-rows: repeat(2, 16px);
  gap: 2px;
  padding: 2px;
  background: var(--inset-bg);
  border: 1px solid var(--border);
  border-radius: 2px;
}
.color-swatch {
  position: relative;
  width: 16px;
  height: 16px;
  border: 1px solid rgba(255,255,255,0.12);
  cursor: pointer;
  padding: 0;
  border-radius: 0;
}
.color-swatch.active {
  outline: 2px solid var(--mint);
  outline-offset: 1px;
  z-index: 1; /* keep the highlight on top of neighboring swatches */
}

/* ---------- compose area ----------
   Note: the send button is positioned absolutely inside this area, carving
   out the bottom-right corner. The compose region is intentionally not a
   perfect rectangle — the bottom-right is occupied by the send button. */
.compose-area {
  position: relative;
  background: #fafafa;
  border-radius: 0;
  overflow: hidden;
  /* Lock the aspect ratio so every message — composed on phone or laptop —
     ends up with the same shape. Width still scales to the available room. */
  aspect-ratio: 480 / 90;
}
.compose-area--flash {
  box-shadow: inset 0 0 0 2px rgba(255, 80, 80, 0.6);
}
#messageInput {
  display: block;
  width: 100%;
  height: 100%;            /* fill the aspect-ratio'd parent */
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  padding: 10px 12px;
  font: inherit;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.45;
  color: #1a1a1a;
  cursor: default;
}
#composeCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: default;
  background: transparent;
  touch-action: none;
}

/* ---------- send button — carved into bottom-right of compose area ---------- */
.send-btn {
  position: absolute;
  bottom: 0;
  right: 0;
  /* Proportional dimensions (16.67% × 33.33% of the 480×90 compose area).
     This way a drawing "under the button" on one device ends up under
     the play button on every other device, regardless of viewport size. */
  width:  calc(80 / 480 * 100%);
  height: calc(30 / 90  * 100%);
  padding: 0;
  background: var(--surface-3);
  /* Default state: no peers connected — text is muted to signal that
     a sent message will only appear locally. .has-peers (set in JS when
     at least one peer is in the room) flips this to the mint accent. */
  color: var(--text-mute);
  border: 1px solid var(--border);
  border-right: none;
  border-bottom: none;
  border-radius: 0;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 0.3px;
  z-index: 2;
}
.has-peers .send-btn {
  color: var(--mint);
}
.send-btn:hover {
  background: var(--surface-3h);
}
.send-btn:active {
  background: var(--surface-3d);
}
.send-arrow {
  font-size: 14px;
  transform: translateY(-1px);
}
