/*
 * Farpad styles. Light and dark follow the device. The pad fills the screen:
 * on a phone, chat, sketch and text are tabs; on a wide screen, chat sits
 * beside whichever of the other two is open.
 */

:root {
  --bg: #f5f5f2;
  --panel: #ffffff;
  --raised: #ecebe6;
  --border: #d9d7d0;
  --text: #1c1c1a;
  --dim: #66645d;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d6efec;
  --warn-bg: #fff4d6;
  --warn: #8a5a00;
  --danger: #b42318;
  --me: #0f766e;
  --me-ink: #ffffff;
  --them: #ecebe6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f24;
    --raised: #262a31;
    --border: #343943;
    --text: #eceae4;
    --dim: #a3a199;
    --accent: #2dd4bf;
    --accent-ink: #062a26;
    --accent-soft: #123b37;
    --warn-bg: #3a2f12;
    --warn: #f3c969;
    --danger: #f97066;
    --me: #2dd4bf;
    --me-ink: #062a26;
    --them: #262a31;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body.in-pad {
  overflow: hidden;
}

a {
  color: var(--accent);
}

h1,
h2 {
  margin: 0 0 8px;
  line-height: 1.2;
}

h2 {
  font-size: 1.1rem;
}

.noscript {
  padding: 24px;
  text-align: center;
}

/* -------------------------------------------------------------- controls */

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:focus-visible,
.tab:focus-visible,
.code-chip:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn.danger-ghost {
  color: var(--danger);
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--dim);
}

.btn.small {
  padding: 6px 10px;
  font-size: 0.875rem;
}

.btn.icon {
  padding: 8px 10px;
}

.btn.wide {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.linklike {
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
}

input[type='text'],
input[type='password'],
textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.field {
  display: block;
  margin: 8px 0 12px;
}

.field span {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 4px;
  color: var(--dim);
}

.field em {
  font-style: normal;
  opacity: 0.8;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row > input {
  flex: 1;
  min-width: 0;
}

.row.center {
  justify-content: center;
}

.hint {
  color: var(--dim);
  font-size: 0.92rem;
  margin: 8px 0;
}

.small {
  font-size: 0.82rem;
}

/* --------------------------------------------------------------- screens */

.screen.narrow {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.hero {
  text-align: center;
  margin: 16px 0 24px;
}

.mark {
  font-size: 44px;
  text-align: center;
}

.hero h1 {
  font-size: 2.2rem;
  letter-spacing: -0.02em;
}

.lede {
  color: var(--dim);
  margin: 0 auto;
  max-width: 34em;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
  box-shadow: var(--shadow);
}

.card.plain {
  background: transparent;
  box-shadow: none;
}

.uses {
  padding-left: 1.1em;
  margin: 8px 0;
}

.uses li {
  margin: 6px 0;
}

.safety-line {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
}

.owner summary {
  cursor: pointer;
  font-weight: 600;
}

.foot {
  text-align: center;
  color: var(--dim);
  font-size: 0.9rem;
  margin-top: 24px;
}

.screen-title {
  text-align: center;
  font-size: 1.5rem;
  margin: 8px 0 16px;
}

.qr {
  width: min(260px, 70vw);
  margin: 0 auto 16px;
  border-radius: 12px;
  overflow: hidden;
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.qr-light {
  fill: #ffffff;
}

.qr-dark {
  fill: #000000;
}

#invite .row {
  margin: 10px 0;
}

.waiting {
  text-align: center;
  font-weight: 600;
  margin: 16px 0;
}

.advice {
  background: var(--warn-bg);
  color: var(--text);
  border-radius: var(--radius);
  padding: 4px 16px;
  font-size: 0.92rem;
}

#invite > .btn.ghost,
#join > .btn.ghost {
  display: block;
  margin: 12px auto 0;
}

#join .hint,
#ended .hint {
  text-align: center;
}

/* ------------------------------------------------------------------- pad */

.pad {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

.padbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.who {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.peer {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sync {
  color: var(--dim);
  font-size: 0.8rem;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border);
  flex: none;
  align-self: center;
}

.dot.on {
  background: #22c55e;
}

.dot.mid {
  background: #eab308;
}

.code-chip {
  border: 1px solid var(--border);
  background: var(--raised);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.code-chip.todo {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}

.code-chip.ok {
  background: var(--accent-soft);
  color: var(--text);
  border-color: transparent;
}

.code-chip:disabled {
  cursor: default;
  opacity: 0.75;
}

.verify {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  text-align: center;
}

.code-big {
  font-size: 2.4rem;
  letter-spacing: 0.15em;
  margin: 8px 0 0;
}

.code-words {
  color: var(--dim);
  margin: 0 0 8px;
}

.verify .hint {
  max-width: 40em;
  margin: 8px auto 12px;
}

.banner {
  padding: 10px 14px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.9rem;
  cursor: pointer;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.tab {
  flex: 1;
  border: 0;
  background: none;
  color: var(--dim);
  font: inherit;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab[aria-selected='true'] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.badge {
  display: inline-block;
  min-width: 1.4em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.75rem;
  line-height: 1.4em;
}

.panes {
  flex: 1;
  min-height: 0;
  display: flex;
}

.pane {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

@media (min-width: 900px) {
  .chat-tab {
    display: none;
  }

  .pane.chat {
    order: 2;
    flex: 0 0 340px;
    border-left: 1px solid var(--border);
  }
}

/* ------------------------------------------------------------------ chat */

.messages {
  list-style: none;
  margin: 0;
  padding: 12px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg,
.secret {
  max-width: 85%;
  display: flex;
  flex-direction: column;
}

.msg.me,
.secret.me {
  align-self: flex-end;
  align-items: flex-end;
}

.from {
  font-size: 0.75rem;
  color: var(--dim);
  margin: 0 6px 2px;
}

.msg .body {
  padding: 8px 12px;
  border-radius: 14px;
  background: var(--them);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.me .body {
  background: var(--me);
  color: var(--me-ink);
}

.secret .body {
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px dashed var(--accent);
  background: var(--panel);
}

.secret-text {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--raised);
  padding: 8px;
  border-radius: 8px;
  margin-bottom: 8px;
  user-select: all;
}

.gone {
  color: var(--dim);
}

.note {
  align-self: center;
  text-align: center;
  color: var(--dim);
  font-size: 0.82rem;
  max-width: 90%;
}

.composer {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  align-items: flex-end;
}

.composer textarea {
  resize: none;
  max-height: 160px;
  padding: 9px 12px;
}

.secret-composer {
  padding: 12px;
  border-top: 2px solid var(--accent);
  background: var(--panel);
}

.secret-composer textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

.secret-head {
  margin: 0 0 8px;
}

.secret-warn {
  background: var(--warn-bg);
  color: var(--warn);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.88rem;
  margin: 0 0 8px;
}

.secret-composer .row {
  justify-content: flex-end;
}

/* ---------------------------------------------------------------- sketch */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.swatches,
.widths {
  display: flex;
  gap: 4px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  cursor: pointer;
  padding: 0;
}

.swatch[aria-checked='true'] {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
}

.width {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.width[aria-checked='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.width-dot {
  display: block;
  border-radius: 50%;
  background: var(--text);
}

#eraserBtn[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.board-wrap {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
}

#board {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 0 0 1px var(--border);
  touch-action: none;
  cursor: crosshair;
}

/* ------------------------------------------------------------------ text */

.toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-size: 0.875rem;
}

.shared-text {
  flex: 1;
  border: 0;
  border-radius: 0;
  resize: none;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.5;
  tab-size: 2;
}

.shared-text.nowrap {
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

/* ----------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(90vw, 480px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 10;
  text-align: center;
}
