/* ==========================================================
   Write page: a phone-style "New Message" composer.
   Laptop: centred phone frame. Phone: fills the screen.
   ========================================================== */

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.stage {
  display: flex;
  justify-content: center;
  padding: 36px 16px 56px;
  overflow: hidden;
}

/* ---------- Phone frame ---------- */

.phone {
  position: relative;
  width: 390px;
  max-width: 100%;
  height: min(780px, calc(100vh - 150px));
  min-height: 560px;
  border-radius: 56px;
  background: var(--surface);
  border: 12px solid #1c1c1e;
  box-shadow: 0 0 0 2px #c7c7cc, 0 30px 60px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.55s cubic-bezier(0.65, 0, 0.35, 1), opacity 0.55s ease;
}

.phone.swipe-out { transform: translateX(-120%); opacity: 0; }

.status-bar {
  position: relative;
  flex: none;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 28px 0 34px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
}

.status-bar .island {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  width: 110px;
  height: 32px;
  border-radius: 20px;
  background: #1c1c1e;
}

.status-bar .icons { display: flex; align-items: center; gap: 5px; }
.status-bar svg { height: 12px; width: auto; fill: currentColor; }

/* ---------- Screen ---------- */

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.compose-top {
  flex: none;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  padding: 6px 14px 4px;
}

.compose-top h1 {
  margin: 0;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 700;
}

.round-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--ink);
}

.round-btn svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; fill: none; }

/* To: row */
.to-row {
  flex: none;
  margin: 10px 14px 0;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.06);
}

.to-label { color: var(--ink-soft); font-size: 1rem; }

.to-row input {
  flex: 1;
  min-width: 0;
  border: 0;
  padding: 6px 0;
  background: transparent;
  box-shadow: none;
  font-size: 1rem;
  border-radius: 0;
}

.to-row input:focus { box-shadow: none; }

.chip {
  font: inherit;
  font-size: 1rem;
  border: 0;
  padding: 4px 11px;
  border-radius: 10px;
  background: var(--chip-bg);
  color: var(--chip-ink);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip[hidden] { display: none; }

/* Thread */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 14px 10px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 4px;
}

.hint {
  align-self: center;
  margin: auto 0;
  max-width: 270px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.hint p { margin: 0 0 8px; }
.hint p:first-child { color: var(--ink); font-weight: 600; font-size: 1rem; }

.thread .bubble {
  font-size: 1.05rem;
  max-width: 80%;
  animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  transform-origin: bottom right;
}

.thread .bubble.pending { opacity: 0.55; }

@keyframes pop {
  from { opacity: 0; transform: translateY(24px) scale(0.7); }
  to { opacity: 1; transform: none; }
}

.thread .status {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.thread .msg-status { margin-top: 2px; }

.compose-error {
  flex: none;
  margin: 0 16px 6px;
  font-size: 0.85rem;
  color: var(--error-ink);
  text-align: center;
}

.compose-error[hidden] { display: none; }

/* Colour tray (opened by +) */
.tray {
  flex: none;
  margin: 0 14px 8px;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 10px 30px rgba(0, 0, 0, 0.1);
  animation: tray-in 0.2s ease both;
}

.tray[hidden] { display: none; }

@keyframes tray-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.tray-title {
  margin: 0 0 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.tray-swatches { display: flex; flex-wrap: wrap; gap: 10px; }

.tray-swatches button {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: var(--sw);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 2px;
}

.tray-swatches button[aria-checked="true"] { outline-color: var(--ink); }
.tray-swatches button:focus-visible { outline-color: var(--np-orange); }

/* Bottom bar: + and the message field */
.compose-bar {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 12px 22px;
}

/* The + shows the current bubble colour */
.plus {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--bubble, var(--b-green));
  color: var(--bubble-ink, #fff);
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--line);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s;
}

.plus:disabled { opacity: 0.4; cursor: default; }

/* First-time tip pointing at the + */
.colour-tip {
  position: relative;
  flex: none;
  align-self: flex-start;
  margin: 0 0 8px 12px;
  padding: 7px 12px;
  border-radius: 12px;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  animation: tray-in 0.25s ease both;
}

.colour-tip::after {
  content: "";
  position: absolute;
  left: 16px;
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: inherit;
  transform: rotate(45deg);
}

.colour-tip[hidden] { display: none; }

.plus svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; fill: none; }
.plus[aria-expanded="true"] { transform: rotate(45deg); }

.compose-bar .field {
  margin: 0;
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  padding: 3px 3px 3px 14px;
}

.field:focus-within { border-color: #c7c7cc; }

.field textarea {
  flex: 1;
  min-height: 34px;
  max-height: 140px;
  border: 0;
  padding: 6px 4px 6px 0;
  resize: none;
  background: transparent;
  font-size: 1rem;
  line-height: 1.35;
  border-radius: 0;
  box-shadow: none;
  overflow-y: auto;
}

.field textarea:focus { box-shadow: none; }

.counter {
  align-self: center;
  font-size: 0.75rem;
  color: var(--ink-soft);
  padding: 0 6px;
}

.counter[hidden] { display: none; }

.send {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: var(--bubble, var(--b-green));
  color: var(--bubble-ink, #fff);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.15s;
}

.send svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; fill: none; }
.send:disabled { opacity: 0.3; cursor: default; }
.send:not(:disabled):active { transform: scale(0.9); }

/* ---------- Phones: fill the screen like the real app ---------- */

@media (max-width: 640px) {
  .compose-page .site-header,
  .compose-page .site-footer,
  .compose-page .demo-banner { display: none; }

  .stage { padding: 0; }

  .phone {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .status-bar { display: none; }

  .compose-top { padding-top: max(10px, env(safe-area-inset-top)); }
  .compose-bar { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .field textarea { font-size: 16px; } /* stops iOS zooming in */
}

@media (prefers-reduced-motion: reduce) {
  .phone, .thread .bubble, .tray { transition: none; animation: none; }
}
