:root {
  color-scheme: light;
  --bg: #f3f0e8;
  --panel: #fffdf8;
  --panel-border: #d8d0c2;
  --text: #202020;
  --muted: #6a6258;
  --accent: #235c49;
  --accent-strong: #183f32;
  --secondary: #75695c;
  --secondary-strong: #5c5248;
  --danger: #a43f2d;
  --shadow: 0 18px 40px rgba(45, 42, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "PingFang SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top right, rgba(35, 92, 73, 0.14), transparent 24%),
    linear-gradient(180deg, #f8f4ec 0%, var(--bg) 100%);
}

.app-shell {
  width: min(980px, calc(100% - 32px));
  margin: 32px auto;
  display: grid;
  gap: 20px;
}

.auth-shell {
  min-height: calc(100vh - 64px);
  place-items: center;
}

.auth-panel {
  width: min(420px, 100%);
}

.auth-form {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.eyebrow,
.meta-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

h1,
h2,
p,
pre,
strong,
span {
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 4vw, 2.8rem);
}

.status-line {
  margin-top: 12px;
  color: var(--accent-strong);
}

.round-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.stats-grid,
.settings-grid {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.settings-grid {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.meta-card {
  min-width: 110px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #f0ece2;
}

.compact-card {
  min-width: 132px;
}

.groups-display {
  min-height: 120px;
  margin-top: 8px;
  padding: 18px;
  border-radius: 18px;
  border: 1px dashed var(--panel-border);
  background: #faf7f0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 2.4rem;
  line-height: 1.9;
  font-family: Consolas, "Courier New", monospace;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

button {
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  padding: 12px 18px;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--accent-strong);
}

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

.button-secondary:hover:not(:disabled) {
  background: var(--secondary-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.input-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
}

.text-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--panel-border);
  font-size: 1rem;
  background: white;
}

.analysis-box {
  margin-top: 18px;
  min-height: 78px;
  padding: 16px;
  border-radius: 16px;
  background: #f8f3eb;
  color: var(--accent-strong);
}

.setting-field {
  display: grid;
}

.settings-divider {
  height: 1px;
  margin: 24px 0 0;
  background: rgba(106, 98, 88, 0.18);
}

.ai-settings-header {
  margin-top: 24px;
}

.checkbox-field {
  align-content: start;
}

.checkbox-field input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 8px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  background: #eef4ef;
  color: var(--accent-strong);
  font-weight: 600;
}

.compact-analysis {
  min-height: 64px;
}


.hero-panel {
  padding: 14px 18px;
}

.hero-top-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.hero-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: stretch;
  flex: 1 1 320px;
}

.current-round-card {
  display: grid;
  gap: 4px;
  min-width: 150px;
  background: #eef4ef;
  color: var(--accent-strong);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.toolbar-row {
  align-items: center;
  justify-content: flex-end;
}

.top-actions {
  margin: 0;
  flex: 0 1 auto;
}

.compact-stats .meta-card {
  padding: 10px 12px;
}

.header-stats {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-top: 12px;
}

.compact-select {
  width: auto;
  min-width: 140px;
}

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

.button-danger:hover:not(:disabled) {
  background: #7e2f22;
}

.modal.hidden {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(32, 32, 32, 0.38);
}

.modal-content {
  width: min(760px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.wide-modal {
  width: min(980px, 100%);
}

.summary-stack {
  display: grid;
  gap: 10px;
}

.mini-note {
  color: var(--muted);
  font-size: 0.95rem;
}

.selected-preview {
  min-height: 52px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px dashed var(--panel-border);
  background: #faf7f0;
  font-family: Consolas, "Courier New", monospace;
  line-height: 1.5;
  word-break: break-word;
}

.free-config-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  margin-top: 18px;
}

.free-groups-display {
  min-height: 200px;
}

.character-picker-modal .modal-content {
  width: min(880px, 100%);
}

.tab-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

.tab-button.is-active {
  background: var(--accent-strong);
}

.tab-panel.hidden {
  display: none;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(58px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

.character-chip {
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  padding: 12px 0;
  font-family: Consolas, "Courier New", monospace;
  font-size: 1rem;
  font-weight: 700;
}

.character-chip:hover:not(:disabled) {
  background: #f5efe5;
}

.character-chip.is-selected {
  background: #235c49;
  color: #fff;
  border-color: #235c49;
}

.picker-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 20px, 980px);
    margin: 20px auto;
  }

  .panel {
    padding: 18px;
  }

  .round-header {
    flex-direction: column;
  }

  .hero-top-row {
    align-items: stretch;
  }

  .hero-summary {
    flex-direction: column;
  }

  .free-config-grid {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }
}
