:root {
  --bg: #f4efe6;
  --bg-accent: radial-gradient(circle at top left, rgba(150, 53, 28, 0.2), transparent 28%),
    radial-gradient(circle at bottom right, rgba(51, 105, 74, 0.18), transparent 24%),
    linear-gradient(180deg, #f8f3eb 0%, #efe4d1 100%);
  --panel: rgba(255, 250, 242, 0.9);
  --panel-strong: #fff9ef;
  --ink: #1f1a17;
  --muted: #675a50;
  --line: rgba(63, 42, 28, 0.14);
  --brand: #8b2e14;
  --brand-strong: #6f1e0c;
  --accent: #2b6a46;
  --shadow: 0 18px 55px rgba(74, 42, 17, 0.12);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Zen Kaku Gothic New", sans-serif;
  color: var(--ink);
  background: var(--bg-accent);
}

button,
input,
select,
textarea {
  font: inherit;
}

.page-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.topbar-title {
  font-size: 0.95rem;
  color: var(--muted);
}

.menu-button {
  display: none;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 242, 0.86);
  cursor: pointer;
}

.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 4px auto;
  background: var(--brand);
  border-radius: 999px;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  width: min(360px, calc(100vw - 24px));
  height: 100vh;
  padding: 20px;
  background: rgba(255, 249, 239, 0.98);
  border-right: 1px solid var(--line);
  box-shadow: 0 18px 55px rgba(74, 42, 17, 0.18);
  transform: translateX(calc(-100% - 16px));
  transition: transform 180ms ease;
  overflow-y: auto;
}

.drawer.is-open {
  transform: translateX(0);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(31, 26, 23, 0.28);
}

.drawer-header,
.drawer-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.drawer-section {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.drawer-link {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: white;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}

.drawer-inline-button,
.drawer-close {
  padding: 10px 14px;
}

.room-history-list {
  display: grid;
  gap: 10px;
}

.room-history-empty {
  padding: 16px;
  border-radius: 16px;
  border: 1px dashed rgba(83, 61, 43, 0.2);
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
}

.room-history-item {
  padding: 14px;
  border-radius: 18px;
  background: white;
  border: 1px solid var(--line);
  display: grid;
  gap: 10px;
}

.room-history-meta {
  display: grid;
  gap: 4px;
}

.room-history-name {
  font-weight: 700;
}

.room-history-id {
  color: var(--muted);
  font-size: 0.88rem;
}

.room-history-time {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.hero {
  padding: 24px 4px 20px;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 10px;
  color: var(--brand);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.78rem;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
}

.layout {
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  padding: 24px;
}

.collapsible-panel[open] {
  padding-bottom: 24px;
}

.collapsible-summary {
  list-style: none;
  cursor: pointer;
}

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

.summary-actions {
  flex-wrap: wrap;
}

.summary-toggle-text {
  color: var(--muted);
  font-size: 0.88rem;
  letter-spacing: 0.08em;
}

.collapsible-summary::after {
  content: "＋";
  margin-left: auto;
  color: var(--brand);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
}

.collapsible-panel[open] > .collapsible-summary::after {
  content: "−";
}

.panel-header,
.actions,
.entry-actions,
.game-switcher {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.config-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 18px;
}

.room-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 18px;
}

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

.subcard {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.subcard h3 {
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.inline-grid,
.entry-grid,
.summary-grid {
  display: grid;
  gap: 12px;
}

.inline-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.92rem;
}

textarea,
input,
select {
  width: 100%;
  border: 1px solid rgba(83, 61, 43, 0.18);
  background: white;
  color: var(--ink);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

textarea:focus,
input:focus,
select:focus {
  border-color: rgba(139, 46, 20, 0.55);
  box-shadow: 0 0 0 4px rgba(139, 46, 20, 0.08);
}

textarea {
  resize: vertical;
  min-height: 170px;
}

.hint {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.7;
}

.mode-chip,
.button {
  border: 0;
  cursor: pointer;
  border-radius: 999px;
  transition: transform 160ms ease, background 160ms ease, color 160ms ease, opacity 160ms ease;
}

.mode-chip {
  padding: 12px 18px;
  background: rgba(255, 250, 242, 0.72);
  color: var(--muted);
  border: 1px solid var(--line);
}

.mode-chip.is-active {
  background: var(--brand);
  color: white;
}

.button {
  padding: 13px 20px;
  background: var(--brand);
  color: white;
  font-weight: 700;
}

.button:hover,
.mode-chip:hover {
  transform: translateY(-1px);
}

.button-ghost {
  background: rgba(255, 255, 255, 0.55);
  color: var(--ink);
  border: 1px solid var(--line);
}

.join-room-form {
  margin-top: 18px;
  display: grid;
  gap: 10px;
}

.room-link-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.room-link-row input {
  flex: 1;
}

.game-panel {
  display: none;
}

.game-panel.is-active {
  display: block;
  animation: panel-in 220ms ease;
}

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

.entry-grid {
  margin-top: 18px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.player-card {
  padding: 18px;
  border-radius: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(250, 239, 225, 0.92));
  border: 1px solid var(--line);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.entry-actions {
  margin-top: 18px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.entry-actions .button {
  min-width: 168px;
}

.results {
  margin-top: 26px;
  display: grid;
  gap: 16px;
}

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

.summary-card {
  padding: 18px;
  border-radius: 20px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.summary-card h3 {
  margin-bottom: 12px;
  font-size: 1rem;
}

.metrics {
  display: grid;
  gap: 10px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed rgba(83, 61, 43, 0.18);
}

.metric-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.metric-row strong {
  font-size: 1.05rem;
}

.history-card {
  overflow: hidden;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: white;
}

.history-card {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid rgba(83, 61, 43, 0.12);
}

thead {
  background: #f7ecdd;
}

tbody tr:nth-child(even) {
  background: rgba(244, 239, 230, 0.5);
}

.history-value {
  display: grid;
  gap: 4px;
}

.history-value strong {
  font-size: 1rem;
  font-weight: 700;
}

.history-value span {
  color: var(--muted);
  font-size: 0.88rem;
}

.empty-state {
  padding: 22px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px dashed rgba(83, 61, 43, 0.2);
  color: var(--muted);
}

.status-banner {
  padding: 14px 16px;
  border-radius: 16px;
  background: rgba(43, 106, 70, 0.1);
  color: var(--accent);
  border: 1px solid rgba(43, 106, 70, 0.15);
}

.status-banner.is-error {
  background: rgba(139, 46, 20, 0.08);
  color: var(--brand-strong);
  border-color: rgba(139, 46, 20, 0.16);
}

@media (max-width: 900px) {
  .room-grid,
  .config-grid {
    grid-template-columns: 1fr;
  }

  .inline-grid {
    grid-template-columns: 1fr;
  }

  .room-link-row,
  .panel-header,
  .actions,
  .game-switcher {
    flex-wrap: wrap;
  }

  .room-link-row > * {
    width: 100%;
  }
}

@media (max-width: 600px) {
  .page-shell {
    width: min(100vw - 16px, 1180px);
    padding: 16px 0 32px;
  }

  .topbar {
    position: sticky;
    top: 8px;
    z-index: 20;
    padding: 8px 0;
    margin-bottom: 6px;
    backdrop-filter: blur(12px);
  }

  .menu-button {
    display: inline-block;
  }

  .hero {
    padding: 8px 2px 12px;
  }

  h1 {
    font-size: clamp(1.8rem, 9vw, 2.4rem);
  }

  .panel {
    padding: 16px;
    border-radius: 20px;
  }

  .subcard,
  .summary-card,
  .player-card {
    padding: 14px;
    border-radius: 16px;
  }

  .panel-header,
  .collapsible-summary,
  .actions,
  .entry-actions,
  .game-switcher {
    gap: 10px;
  }

  .summary-toggle-text {
    display: none;
  }

  .collapsible-summary::after {
    margin-left: 0;
  }

  .button,
  .mode-chip {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .topbar .button,
  .topbar .mode-chip,
  .menu-button {
    width: auto;
  }

  .actions .button,
  .entry-actions .button {
    min-width: 0;
  }

  .room-link-row {
    gap: 10px;
  }

  th,
  td {
    padding: 12px 10px;
    font-size: 0.92rem;
    white-space: nowrap;
  }
}
