:root {
  --bg-start: #fffdf8;
  --bg: #f4f0e8;
  --bg-end: #e7dccf;
  --ink: #1f2a37;
  --accent: #0f766e;
  --accent-2: #c2410c;
  --paper: #fffdf8;
  --line: #d2c7b9;
  --danger: #b91c1c;
  --nav-bg: rgba(255, 252, 245, 0.8);
  --panel-bg: #fffdf8;
  --panel-shadow: 0 8px 24px rgba(16, 24, 40, 0.08);
  --pill-bg: #eef6f5;
  --control-bg: #fff9f0;
  --toolbar-bg: #fffaf4;
  --editor-bg: #fff;
  --editor-border: #b7ac9d;
  --input-bg: #fff;
  --input-border: #b7ac9d;
  --subtle-bg: #d5edea;
  --subtle-ink: #083d39;
  --muted: #4b5563;
  --placeholder: #8a94a6;
  --quote-ink: #475569;
  --card-bg: #fffcf8;
  --focus-ring: rgba(15, 118, 110, 0.35);
  --focus-border: #0f766e;
  --danger-soft-bg: #fff7f7;
  --danger-soft-border: #f2b8b8;
}

* {
  box-sizing: border-box;
}

body.theme-paper {
  --bg-start: #fffdf8;
  --bg: #f4f0e8;
  --bg-end: #e7dccf;
}

body.theme-copper {
  --bg-start: #fff7ee;
  --bg: #f2e3d2;
  --bg-end: #d7b69b;
  --ink: #2f2218;
  --accent: #9a3412;
  --accent-2: #78350f;
  --paper: #fff7ef;
  --line: #d7b69c;
  --nav-bg: rgba(255, 244, 232, 0.88);
  --panel-bg: #fff9f2;
  --panel-shadow: 0 10px 28px rgba(75, 41, 17, 0.14);
  --pill-bg: #f4e4d4;
  --control-bg: #fff3e7;
  --toolbar-bg: #fff1e2;
  --editor-bg: #fffdf8;
  --editor-border: #c69d7d;
  --input-border: #c69d7d;
  --subtle-bg: #f1d6bf;
  --subtle-ink: #5e2f0c;
  --muted: #6a4b35;
  --placeholder: #9b7f6b;
  --quote-ink: #6b4b37;
  --card-bg: #fff6ee;
  --focus-ring: rgba(154, 52, 18, 0.3);
  --focus-border: #9a3412;
}

body.theme-forest {
  --bg-start: #f4fbf5;
  --bg: #e6efe8;
  --bg-end: #c9dccf;
  --ink: #1f3a2c;
  --accent: #166534;
  --accent-2: #365314;
  --paper: #f6fbf7;
  --line: #b7d2be;
  --nav-bg: rgba(242, 250, 244, 0.86);
  --panel-bg: #f7fcf8;
  --panel-shadow: 0 10px 26px rgba(12, 56, 30, 0.12);
  --pill-bg: #e3f2e7;
  --control-bg: #eef8f0;
  --toolbar-bg: #edf8f0;
  --editor-bg: #fbfefc;
  --editor-border: #8db39a;
  --input-border: #8db39a;
  --subtle-bg: #cde8d5;
  --subtle-ink: #124628;
  --muted: #3f5f4c;
  --placeholder: #6f8e7b;
  --quote-ink: #355745;
  --card-bg: #f5fbf7;
  --focus-ring: rgba(22, 101, 52, 0.3);
  --focus-border: #166534;
}

body.theme-arcade {
  --bg-start: #f6fffb;
  --bg: #d7f3ea;
  --bg-end: #bde8ff;
  --ink: #0f172a;
  --accent: #0ea5e9;
  --accent-2: #ea580c;
  --paper: #f8fffe;
  --line: #99d4c4;
  --nav-bg: rgba(240, 255, 251, 0.82);
  --panel-bg: #fbfffe;
  --panel-shadow: 0 12px 28px rgba(14, 116, 144, 0.18);
  --pill-bg: #dff6ef;
  --control-bg: #eefaf6;
  --toolbar-bg: #eaf9f5;
  --editor-bg: #ffffff;
  --editor-border: #72b4a0;
  --input-border: #72b4a0;
  --subtle-bg: #bdeee1;
  --subtle-ink: #0b3a34;
  --muted: #35566b;
  --placeholder: #6a8899;
  --quote-ink: #35566b;
  --card-bg: #f7fffd;
  --focus-ring: rgba(14, 165, 233, 0.35);
  --focus-border: #0ea5e9;
}

body.theme-midnight {
  --bg-start: #111a2c;
  --bg: #0b1220;
  --bg-end: #090f1a;
  --ink: #e6edf8;
  --accent: #38bdf8;
  --accent-2: #f59e0b;
  --paper: #121b2d;
  --line: #2a3a55;
  --danger: #ef4444;
  --nav-bg: rgba(11, 18, 32, 0.9);
  --panel-bg: #121b2d;
  --panel-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --pill-bg: #1b2a44;
  --control-bg: #162238;
  --toolbar-bg: #1a2942;
  --editor-bg: #0f1829;
  --editor-border: #2f466d;
  --input-bg: #0d1728;
  --input-border: #2f466d;
  --subtle-bg: #263a5b;
  --subtle-ink: #dce8ff;
  --muted: #9fb2cf;
  --placeholder: #6f86a8;
  --quote-ink: #b7c8df;
  --card-bg: #162238;
  --focus-ring: rgba(56, 189, 248, 0.35);
  --focus-border: #38bdf8;
  --danger-soft-bg: #2a1a23;
  --danger-soft-border: #5f2d3c;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  background: radial-gradient(circle at 10% 10%, var(--bg-start) 0%, var(--bg) 55%, var(--bg-end) 100%);
  color: var(--ink);
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.main-nav {
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--nav-bg);
  backdrop-filter: blur(4px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--ink);
}

.nav-links {
  display: flex;
  gap: 12px;
  align-items: center;
}

.nav-user-pill {
  background: var(--pill-bg);
}

.hero-shell,
.page-shell,
.auth-shell {
  width: min(1040px, 95%);
  margin: 24px auto 60px;
  display: grid;
  gap: 16px;
}

.hero-card,
.panel,
.auth-card {
  background: var(--panel-bg);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--panel-shadow);
}

.panel-large textarea {
  min-height: 340px;
}

.write-shell {
  width: min(1320px, 97%);
  margin: 16px auto 40px;
  display: grid;
  gap: 14px;
}

.write-header-panel {
  position: sticky;
  top: 72px;
  z-index: 5;
}

.write-controls-panel .control-card {
  background: var(--control-bg);
}

.write-editor-panel {
  min-height: 68vh;
  display: grid;
  gap: 12px;
}

.editor-toolbar {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--toolbar-bg);
}

.writer-editor {
  min-height: 52vh;
  border: 1px solid var(--editor-border);
  border-radius: 10px;
  padding: 16px 18px;
  line-height: 1.75;
  font-size: 1.04rem;
  background: var(--editor-bg);
  overflow-y: auto;
}

body.write-page:not(.zen-mode) .write-shell {
  margin: 10px auto 24px;
  gap: 10px;
}

body.write-page:not(.zen-mode) .write-header-panel,
body.write-page:not(.zen-mode) .write-controls-panel {
  padding: 14px;
}

body.write-page:not(.zen-mode) .write-header-panel h1 {
  margin: 0 0 6px;
  font-size: clamp(1.45rem, 2.2vw, 2rem);
}

body.write-page:not(.zen-mode) .write-header-panel p {
  margin: 0;
}

body.write-page:not(.zen-mode) .write-controls-panel .controls-grid {
  gap: 10px;
}

body.write-page:not(.zen-mode) .write-controls-panel .control-card {
  padding: 10px;
}

body.write-page:not(.zen-mode) .write-editor-panel {
  min-height: calc(100vh - 245px);
  gap: 10px;
}

body.write-page:not(.zen-mode) .writer-editor {
  min-height: calc(100vh - 360px);
  padding: 14px 16px;
  line-height: 1.6;
}

.writer-editor:focus {
  outline: 2px solid var(--focus-ring);
  border-color: var(--focus-border);
}

.writer-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--placeholder);
}

.writer-editor blockquote {
  margin: 0.6rem 0;
  border-left: 3px solid var(--line);
  padding-left: 10px;
  color: var(--quote-ink);
}

body.zen-mode .main-nav,
body.zen-mode .write-header-panel,
body.zen-mode .write-controls-panel,
body.zen-mode .writer-milestones-panel {
  display: none;
}

.zen-exit-floating {
  display: none;
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 30;
}

body.zen-mode .zen-exit-floating {
  display: inline-flex;
}

body.write-page.zen-mode {
  height: 100vh;
  overflow: hidden;
}

body.zen-mode .write-shell {
  margin: 0 auto;
  width: min(1280px, 100%);
  height: 100vh;
  max-height: 100vh;
  padding: 8px;
}

body.zen-mode .write-editor-panel {
  min-height: 0;
  height: calc(100vh - 16px);
  margin: 0;
  gap: 6px;
  overflow: hidden;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

body.zen-mode .session-status {
  font-size: 0.8rem;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
}

body.zen-mode .writer-editor {
  min-height: 0;
  height: 100%;
  line-height: 1.7;
  font-size: 1.08rem;
}

.panel-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-card h1 {
  font-size: clamp(2rem, 3vw, 3rem);
  margin: 0.4rem 0;
}

.hero-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.lead {
  font-size: 1.06rem;
  max-width: 60ch;
}

.grid-three {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kicker {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  color: var(--accent-2);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  padding: 9px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.button:hover {
  filter: brightness(1.1);
  text-decoration: none;
}

.button.subtle {
  background: var(--subtle-bg);
  color: var(--subtle-ink);
}

.button.danger {
  background: var(--danger);
}

.is-hidden {
  display: none !important;
}

.is-disabled-control,
.button.is-disabled-control {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
  filter: grayscale(0.2);
}

.muted {
  color: var(--muted);
}

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

.controls-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.control-card {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: var(--control-bg);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  margin-bottom: 10px;
  background: var(--input-bg);
  color: var(--ink);
}

.stack {
  display: grid;
  gap: 8px;
}

.alert {
  border: 1px solid #f5b4b4;
  background: #fff5f5;
  color: #831843;
  border-radius: 8px;
  padding: 10px;
}

.session-status {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
}

#writerInput {
  min-height: 320px;
  resize: vertical;
  font-size: 1.02rem;
  line-height: 1.6;
}

#coeditInput {
  min-height: 420px;
  resize: vertical;
  font-size: 1rem;
  line-height: 1.6;
}

#deleteRecoveryMessage {
  white-space: pre-line;
}

.mono {
  font-family: 'IBM Plex Mono', monospace;
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 10px;
}

.list.compact {
  gap: 4px;
}

.list.compact li {
  border-bottom: 1px dashed var(--line);
  padding-bottom: 4px;
}

.cards-list li,
.writing-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: var(--card-bg);
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.writing-preview {
  white-space: pre-wrap;
  font-size: 0.95rem;
  font-family: 'IBM Plex Sans', sans-serif;
}

.pill {
  display: inline-block;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.table th,
.table td {
  border: 1px solid var(--line);
  text-align: center;
  padding: 6px;
}

.leaderboard li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px dashed var(--line);
  padding: 8px 0;
}

.group-actions-row {
  margin-top: 8px;
}

.collapsible-details {
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 8px;
  background: var(--control-bg);
}

.collapsible-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 8px;
}

.collapsible-summary::-webkit-details-marker {
  display: none;
}

.collapsible-title {
  font-size: 1.05rem;
}

.collapsible-summary::after {
  content: 'Show';
  font-size: 0.85rem;
  color: var(--muted);
}

.collapsible-details[open] .collapsible-summary::after {
  content: 'Hide';
}

.members-scroll-shell {
  max-height: 52vh;
  overflow-y: auto;
  padding: 6px;
}

.writing-scroll-shell {
  max-height: 62vh;
  overflow-y: auto;
  padding: 6px;
}

.milestone-item {
  border-bottom: 1px dashed var(--line);
  padding: 6px 0;
}

.milestone-item:last-child {
  border-bottom: none;
}

.danger {
  border-color: var(--danger-soft-border);
  background: var(--danger-soft-bg);
}

.auth-shell {
  max-width: 520px;
}

.chat-list {
  max-height: 320px;
  overflow-y: auto;
}

.chat-message-item {
  background: var(--card-bg);
}

.chat-message-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.chat-message-body {
  margin: 0;
  white-space: pre-wrap;
}

.chat-compose textarea {
  margin: 0;
  min-height: 88px;
}

.open-live-layout {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 3fr) minmax(230px, 0.85fr);
  align-items: start;
}

body.open-live-page .page-shell.open-live-shell {
  width: min(1600px, 99%);
  margin: 10px auto 20px;
  gap: 8px;
}

body.open-live-page .panel {
  padding: 12px;
}

.open-live-editor-panel {
  display: grid;
  gap: 6px;
  min-height: calc(100vh - 118px);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
}

.open-live-top-row {
  align-items: flex-end;
}

.open-live-top-controls {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.open-live-top-control {
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  padding: 5px 6px;
}

.open-live-top-control label {
  margin-bottom: 2px;
  font-size: 0.72rem;
}

.open-live-top-control .inline-row {
  gap: 5px;
}

.open-live-top-control input,
.open-live-top-control select {
  margin: 0;
  padding: 5px 7px;
  height: 30px;
  font-size: 0.82rem;
}

#openLiveDisplayName {
  width: 140px;
}

#openLiveGoalType {
  width: 95px;
}

#openLiveGoalValue {
  width: 72px;
}

.open-live-top-control .button {
  padding: 6px 9px;
  font-size: 0.8rem;
}

.open-live-editor-panel .session-status {
  gap: 10px;
  font-size: 0.82rem;
}

.open-live-setup-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(170px, 1fr));
}

.open-live-setup-grid .control-card {
  padding: 8px;
}

.open-live-setup-grid .control-card label {
  margin-bottom: 4px;
}

.open-live-setup-grid input,
.open-live-setup-grid select {
  margin-bottom: 6px;
  padding: 7px 8px;
}

.open-live-toolbar {
  padding: 6px;
  gap: 6px;
}

.open-live-toolbar .button {
  padding: 7px 10px;
  font-size: 0.9rem;
}

.open-live-editor-panel .writer-editor {
  min-height: 0;
  height: 100%;
  font-size: 1.06rem;
}

.open-live-sidepanel {
  align-self: start;
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 92px);
  display: grid;
  gap: 6px;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.open-live-sidepanel .control-card {
  padding: 8px;
}

#openLiveOwnerTools label {
  margin-bottom: 4px;
  font-size: 0.82rem;
}

#openLiveOwnerTools input {
  margin-bottom: 6px;
  padding: 6px 8px;
}

.open-live-room-meta h1 {
  margin: 0 0 4px;
  font-size: clamp(1.08rem, 1.4vw, 1.35rem);
}

.open-live-room-meta p {
  margin: 0;
  font-size: 0.86rem;
}

.open-live-side-status {
  margin-top: 6px;
  gap: 6px;
  font-size: 0.76rem;
}

.open-live-sidepanel .button {
  padding: 7px 9px;
  font-size: 0.85rem;
}

.open-live-sidepanel h2 {
  margin: 0;
  font-size: 0.96rem;
}

.open-live-sidepanel select {
  margin-bottom: 0;
  width: 128px;
  padding: 6px 8px;
  font-size: 0.84rem;
}

.open-live-sidepanel .cards-list {
  max-height: none;
  min-height: 0;
  overflow-y: auto;
  gap: 6px;
}

.open-live-sidepanel .cards-list li {
  padding: 7px 8px;
  border-radius: 8px;
}

.open-live-sidepanel .cards-list li strong {
  font-size: 0.9rem;
}

.open-live-sidepanel .cards-list li .muted {
  font-size: 0.78rem;
  line-height: 1.2;
}

.open-live-sidepanel .pill {
  padding: 3px 7px;
  font-size: 0.74rem;
}

.open-live-thumb-btn {
  min-width: 34px;
  padding: 4px 7px;
  font-size: 0.78rem;
}

.open-live-note {
  margin: 0;
  font-size: 0.86rem;
}

.open-live-self {
  border: 1px solid var(--focus-border);
  box-shadow: 0 0 0 2px var(--focus-ring);
}

@media (max-width: 700px) {
  .main-nav {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }

  .panel-top {
    flex-direction: column;
  }

  body.write-page:not(.zen-mode) .write-editor-panel {
    min-height: 62vh;
  }

  body.write-page:not(.zen-mode) .writer-editor {
    min-height: 50vh;
    line-height: 1.55;
  }

  .open-live-layout {
    grid-template-columns: 1fr;
  }

  .open-live-sidepanel {
    position: static;
  }

  .open-live-top-row {
    flex-direction: column;
    align-items: stretch;
  }

  .open-live-top-controls {
    justify-content: flex-start;
  }

  .open-live-editor-panel .writer-editor {
    min-height: 60vh;
  }

  .open-live-top-control {
    width: 100%;
  }

  #openLiveDisplayName,
  #openLiveGoalType,
  #openLiveGoalValue {
    width: 100%;
  }
}
