:root {
  --bg: #12100ee6;
  --panel: #1c1814cc;
  --ink: #f6ead6;
  --muted: #b9a894;
  --accent: #e07a3d;
  --navy: #1e3a5fcc;
  --danger: #c45c28;
  --light: #e8d5b0;
  --dark: #5a3d28;
  --glass: blur(16px);
  font-family: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(1200px 800px at 20% 0%, #2a211ccc, #12100e 55%);
  color: var(--ink);
}

header, #log, #drawer, .thread, .modal, .brief-box, #slash-menu {
  backdrop-filter: var(--glass);
  -webkit-backdrop-filter: var(--glass);
}

body {
  display: flex;
  flex-direction: column;
  max-width: 42rem;
  margin: 0 auto;
  min-height: 100dvh;
  height: 100dvh;
  padding: 0.75rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg);
  flex-shrink: 0;
  padding-bottom: 0.4rem;
}

.brand { flex: 1; min-width: 0; }

h1 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: 0.04em;
}

.sub {
  color: var(--muted);
  font-size: 0.8rem;
}

#face {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 128px;
  height: 128px;
  background: #0b0a09;
  border: 2px solid var(--navy);
  border-radius: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 2.6rem;
  height: 2.6rem;
  background: var(--navy);
  color: var(--ink);
  border: 0;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 0;
}

.icon-btn span {
  display: block;
  width: 1.15rem;
  height: 2px;
  background: var(--ink);
}

#drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100dvh;
  width: min(18rem, 84vw);
  background: var(--panel);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 4.5rem 1rem 1rem;
  box-shadow: -8px 0 24px #0008;
}

#drawer.hidden, #drawer-backdrop.hidden, .hidden { display: none; }

#drawer-backdrop {
  position: fixed;
  inset: 0;
  background: #0007;
  z-index: 40;
}

#drawer button {
  background: var(--navy);
  color: var(--ink);
  text-align: left;
}

#app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

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

.screen.hidden { display: none; }

.screen-lead {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.4rem 0;
}

#log {
  flex: 1;
  overflow-y: auto;
  margin: 0.5rem 0;
  padding: 0.5rem;
  background: var(--panel);
  border-radius: 8px;
  min-height: 8rem;
}

.msg {
  margin: 0.5rem 0;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  max-width: 86%;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.you { background: var(--navy); margin-left: auto; border-bottom-right-radius: 4px; }
.msg.felix { background: #2a211c; border-bottom-left-radius: 4px; }

html[data-theme="sailfish"] .msg.felix { background: #252830; }
html[data-theme="sailfish"] .msg.you { background: #005b9a; }

.msg-time {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.sendbar {
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
}

.sendbar textarea {
  flex: 1;
  min-height: 44px;
  max-height: 7rem;
  resize: none;
}

#more-sheet {
  background: var(--panel);
  border-radius: 12px;
  padding: 0.6rem;
  margin-top: 0.4rem;
}

.brief-box {
  white-space: pre-wrap;
  background: var(--panel);
  padding: 0.7rem;
  border-radius: 10px;
  max-height: 28vh;
  overflow: auto;
  font-size: 0.8rem;
}

form#composer, .row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

input, button, textarea {
  font: inherit;
  color: var(--ink);
}

textarea, input[type="text"], input[type="password"] {
  background: var(--panel);
  border: 1px solid #3a322c;
  border-radius: 6px;
  padding: 0.5rem;
  width: 100%;
}

textarea {
  flex: 1;
  min-height: 3rem;
  resize: vertical;
}

button {
  background: var(--accent);
  color: #12100e;
  border: 0;
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  font-weight: 650;
}

button.secondary {
  background: var(--navy);
  color: var(--ink);
}

#setup {
  background: var(--panel);
  padding: 1rem;
  border-radius: 8px;
  overflow-y: auto;
}

label { display: block; margin: 0.5rem 0 0.2rem; font-size: 0.85rem; color: var(--muted); }

.privacy {
  font-size: 0.75rem;
  color: var(--muted);
  line-height: 1.4;
}

#status { font-size: 0.75rem; color: var(--muted); }

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(100%, 24rem);
  margin: 0.4rem auto;
  border: 2px solid var(--navy);
  aspect-ratio: 1;
  flex-shrink: 0;
}

.sq {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.1rem, 5vw, 1.8rem);
  user-select: none;
}

.sq.light { background: var(--light); color: #1a120c; }
.sq.dark { background: var(--dark); color: var(--ink); }
.sq.selected { outline: 3px solid var(--accent); outline-offset: -3px; }
.sq.legal { box-shadow: inset 0 0 0 3px #e07a3d99; }

#chess-status {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

#doc-list, #session-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.4rem 0;
}

#doc-list button, #session-list button {
  background: var(--navy);
  color: var(--ink);
  font-weight: 500;
}

#doc-source, #doc-preview {
  flex: 1;
  min-height: 7rem;
  overflow: auto;
}

#doc-preview {
  background: #0b0a09;
  color: var(--ink);
  padding: 0.6rem;
  border-radius: 6px;
  white-space: pre-wrap;
  font-size: 0.8rem;
}

#qr-video {
  width: 100%;
  max-height: 14rem;
  background: #000;
  border-radius: 8px;
}

#pairing-qr {
  display: flex;
  justify-content: center;
  padding: 0.75rem;
  background: #fff;
  border-radius: 8px;
  margin: 0.5rem 0;
}

#pairing-qr svg { width: min(16rem, 100%); height: auto; }

#doc-name, #session-input, #doc-source, #home-search { width: 100%; }

.nav-label {
  margin: 0.8rem 0 0.2rem;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

#update-bar {
  background: var(--navy);
  color: var(--ink);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.8rem;
  margin-bottom: 0.4rem;
}

.modes {
  display: flex;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.chip {
  background: var(--navy);
  color: var(--ink);
  min-height: 44px;
  font-weight: 500;
}

.chip.on {
  background: var(--accent);
  color: #12100e;
}

form#composer button[type="submit"] {
  min-height: 44px;
  min-width: 4.5rem;
}

form#composer textarea {
  min-height: 44px;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.thread {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #3a322c;
  padding: 0.7rem;
  font-weight: 500;
}

.thread .meta {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 400;
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tts-lab {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0;
}

input[type="search"] {
  background: var(--panel);
  border: 1px solid #3a322c;
  border-radius: 6px;
  padding: 0.6rem;
  min-height: 44px;
}

#job-progress {
  display: block;
  width: 100%;
  height: 6px;
  margin-top: 0.35rem;
  accent-color: var(--accent);
}

#job-progress.hidden { display: none; }

#slash-menu {
  position: fixed;
  left: 50%;
  bottom: 6.5rem;
  transform: translateX(-50%);
  width: min(36rem, calc(100vw - 1.5rem));
  background: var(--panel);
  border: 1px solid var(--navy);
  border-radius: 8px;
  z-index: 60;
  max-height: 40vh;
  overflow-y: auto;
  padding: 0.35rem;
}

#slash-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  padding: 0.65rem 0.7rem;
}

#slash-menu button .meta {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
}

#plan-modal {
  position: fixed;
  inset: 0;
  background: #0008;
  z-index: 70;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
}

#plan-modal.hidden { display: none; }

#plan-modal .modal {
  background: var(--panel);
  border-radius: 12px;
  padding: 1rem;
  width: min(36rem, 100%);
  max-height: 88dvh;
  overflow-y: auto;
}

#plan-modal h2 {
  margin: 0 0 0.6rem;
  font-size: 1.05rem;
}

.plan-point {
  display: flex;
  gap: 0.4rem;
  margin: 0.4rem 0;
}

.plan-point input { flex: 1; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
  gap: 0.6rem;
  overflow-y: auto;
  padding: 0.3rem 0 1rem;
}

.photo-tile {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--panel);
  color: var(--ink);
  padding: 0.4rem;
  min-height: 0;
}

.photo-tile img {
  width: 100%;
  height: 7.5rem;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
}

#photo-view {
  position: fixed;
  inset: 0;
  background: #000c;
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#photo-view.hidden { display: none; }

#photo-full {
  max-width: 100%;
  max-height: 80dvh;
  object-fit: contain;
}

select {
  background: var(--panel);
  color: var(--ink);
  border: 1px solid #3a322c;
  border-radius: 6px;
  padding: 0.65rem;
  min-height: 44px;
  width: 100%;
}

html[data-theme="sailfish"] {
  --bg: #111218cc;
  --panel: #1c1d24b8;
  --ink: #f4f5f7;
  --muted: #8e93a0;
  --accent: #00bde3;
  --navy: #005b9acc;
  --danger: #e60032;
  --light: #d0f3fb;
  --dark: #00344f;
  font-family: "Source Sans 3", "Source Sans Pro", "Segoe UI", system-ui, sans-serif;
}

html[data-theme="sailfish"] body {
  background: radial-gradient(1000px 700px at 80% 0%, #004e8a66, #111218 50%);
}

html[data-theme="sailfish"] header {
  border-bottom: 1px solid #2c313c;
}

html[data-theme="sailfish"] button {
  border-radius: 20px;
}

html[data-theme="sailfish"] #drawer {
  border-radius: 0 0 0 24px;
}
html[data-theme="sailfish"] #drawer button {
  min-height: 48px;
  padding-left: 1rem;
}
html[data-theme="sailfish"] #face {
  border-color: var(--accent);
  border-radius: 12px;
}
