:root {
  color-scheme: light;
  --paper: #f7edd8;
  --paper-deep: #ead7ad;
  --ink: #252018;
  --muted: #6f5d42;
  --line: #a78342;
  --gold: #d9a736;
  --red: #9e342d;
  --red-deep: #6f211e;
  --blue: #267a95;
  --green: #3e7754;
  --shadow: 0 14px 34px rgb(61 42 19 / 18%);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgb(116 72 32 / 10%) 0 1px, transparent 1px 34px),
    linear-gradient(180deg, #fbf5e7 0%, var(--paper) 48%, #e5cf9f 100%);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  font-size: 17px;
}

button,
select,
input {
  font: inherit;
}

button,
select,
input[type="text"] {
  border: 2px solid #8a6934;
  border-radius: 8px;
}

button {
  min-height: 46px;
  padding: 10px 16px;
  background: #fff8e8;
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 3px 0 #a97b2c;
}

button:hover:not(:disabled),
button:focus-visible {
  background: #ffe5a7;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  box-shadow: none;
}

select,
input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  background: #fffaf0;
  color: var(--ink);
}

.app {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.title-panel,
.setup-card,
.board-section,
.side-panel section,
.log-panel,
.control-panel,
.result-header,
.results-output {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: rgb(255 250 238 / 90%);
  box-shadow: var(--shadow);
}

.title-panel {
  padding: clamp(22px, 4vw, 44px);
  background:
    linear-gradient(180deg, rgb(255 255 255 / 76%), rgb(255 245 219 / 92%)),
    radial-gradient(circle at 18% 22%, rgb(217 167 54 / 28%), transparent 34%);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--red-deep);
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: clamp(42px, 7vw, 78px);
  line-height: 1.05;
}

h1 span {
  color: var(--red-deep);
  font-size: 0.62em;
}

h2,
h3 {
  margin: 0;
}

.lead {
  max-width: 920px;
  margin: 18px 0 0;
  font-size: clamp(18px, 2vw, 23px);
  line-height: 1.75;
}

.setup-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.setup-card {
  padding: 18px;
}

.setup-card h2 {
  margin-bottom: 14px;
  font-size: 22px;
}

.field-label {
  display: block;
  margin: 14px 0 6px;
  color: var(--muted);
  font-weight: 800;
}

.name-fields {
  display: grid;
  gap: 10px;
}

.name-row {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
  align-items: center;
}

.name-badge {
  border-radius: 8px;
  padding: 8px;
  background: #f4d37d;
  text-align: center;
  font-weight: 900;
}

.online-card p {
  line-height: 1.7;
}

.small-note {
  color: var(--muted);
  font-size: 0.92rem;
}

.online-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.online-status {
  border-left: 5px solid var(--blue);
  margin: 14px 0 0;
  padding: 8px 10px;
  background: #e8f6f8;
  color: #21485a;
  font-weight: 800;
  line-height: 1.55;
}

.online-status.connected {
  border-left-color: var(--green);
  background: #ebf5e7;
  color: #28523a;
}

.online-status.error {
  border-left-color: var(--red);
  background: #f5ded5;
  color: #6f211e;
}

.title-actions,
.result-actions,
.control-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.online-game-controls {
  display: grid;
  width: 100%;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  gap: 8px;
  align-items: center;
  border-top: 2px solid #c49c58;
  margin-top: 6px;
  padding-top: 12px;
}

.online-game-controls label,
.online-game-controls span {
  color: var(--muted);
  font-weight: 900;
}

.online-game-controls span.connected {
  color: var(--green);
}

.online-game-controls span.error {
  color: var(--red);
}

.primary-button {
  border-color: #744411;
  background: linear-gradient(180deg, #ffe7a1, #e2a52d);
  color: #271804;
}

.game-header,
.result-header {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 16px 18px;
}

.game-header h2,
.result-header h2 {
  font-size: clamp(26px, 4vw, 42px);
}

.turn-banner {
  max-width: 640px;
  border: 2px solid #915030;
  border-radius: 8px;
  padding: 12px;
  background: #fff3d2;
  font-size: 20px;
  font-weight: 900;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 370px;
  gap: 14px;
}

.board-section {
  min-width: 0;
  padding: 14px;
}

.toolbar {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.dice-panel,
.event-card {
  border: 2px solid #bc924c;
  border-radius: 8px;
  background: #fff8e6;
  padding: 12px;
}

.dice-panel {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  align-items: center;
}

.dice-result {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border: 3px solid #744411;
  border-radius: 8px;
  background: #fffdf7;
  font-size: 38px;
}

.dice-result.rolling {
  animation: dice-pop 0.34s ease-in-out infinite alternate;
}

@keyframes dice-pop {
  from {
    transform: translateY(0) rotate(-5deg);
  }
  to {
    transform: translateY(-4px) rotate(5deg);
  }
}

.event-card h3 {
  margin-bottom: 8px;
  color: var(--red-deep);
  font-size: 22px;
}

.event-card p {
  margin: 8px 0;
  line-height: 1.65;
}

.question-box {
  border-left: 5px solid var(--blue);
  padding: 8px 10px;
  background: #e8f6f8;
  font-weight: 800;
}

.section-heading {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  justify-content: space-between;
  margin: 0 0 10px;
}

.section-heading p {
  margin: 0;
  color: var(--muted);
  font-weight: 800;
}

.board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.space {
  position: relative;
  display: grid;
  min-height: 132px;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
  border: 2px solid #b7904c;
  border-radius: 8px;
  padding: 8px;
  background: #fffaf0;
}

.space.story,
.space.choice {
  border-color: #b86135;
  background: #fff2d3;
}

.space.crisis {
  border-color: var(--red-deep);
  background: #f5ded5;
}

.space.recovery {
  border-color: var(--blue);
  background: #e8f6f8;
}

.space.selinuntius {
  border-color: var(--green);
  background: #ebf5e7;
}

.space.king {
  border-color: #734091;
  background: #f1e6f6;
}

.space.goal {
  border-color: #b07b00;
  background: #ffe7a1;
}

.space.current-turn {
  outline: 4px solid var(--red);
  outline-offset: 2px;
}

.space-id {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.space-name {
  font-weight: 900;
  line-height: 1.35;
}

.space-icon {
  font-size: 24px;
}

.tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 26px;
}

.token {
  border-radius: 7px;
  padding: 3px 5px;
  background: #273341;
  color: #fff;
  font-size: 0.84rem;
  font-weight: 900;
}

.token.active {
  background: var(--red);
}

.side-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.side-panel section {
  padding: 14px;
}

.status-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.player-card {
  border: 2px solid #b7904c;
  border-radius: 8px;
  padding: 10px;
  background: #fffaf0;
}

.player-card.active {
  border-color: var(--red);
  box-shadow: inset 0 0 0 3px rgb(158 52 45 / 18%);
}

.player-card.finished {
  background: #edf7e9;
}

.player-card.failed {
  background: #f5ded5;
}

.player-head {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-weight: 900;
}

.computer-label {
  border-radius: 999px;
  padding: 3px 8px;
  background: #e8f1f7;
  color: #285f7e;
  font-size: 0.82rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  font-size: 0.93rem;
}

.stat {
  border-radius: 8px;
  padding: 6px;
  background: #f4ead0;
  font-weight: 800;
}

.choice-buttons {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.choice-buttons .choice-button {
  min-height: 58px;
  text-align: left;
  line-height: 1.5;
}

.choice-summary {
  display: block;
  color: #55452d;
  font-size: 0.92rem;
  font-weight: 700;
}

.bottom-panels {
  display: grid;
  grid-template-columns: 410px minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}

.control-panel {
  align-content: start;
  margin-top: 0;
  padding: 14px;
}

.log-panel {
  min-height: 180px;
  padding: 14px;
}

.event-log {
  display: grid;
  max-height: 260px;
  gap: 8px;
  margin: 12px 0 0;
  padding-left: 24px;
  overflow: auto;
}

.event-log li {
  line-height: 1.55;
}

.results-output {
  padding: 16px;
}

.result-table-wrap {
  overflow-x: auto;
}

.result-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: #fffaf0;
}

.result-table th,
.result-table td {
  border: 1px solid #b7904c;
  padding: 8px;
  text-align: left;
  vertical-align: top;
}

.result-table th {
  background: #f0d28b;
}

.reflection {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}

.reflection li {
  line-height: 1.6;
}

.toast {
  display: inline-block;
  margin-left: 8px;
  color: var(--green);
  font-weight: 900;
}

@media (max-width: 1120px) {
  .setup-grid,
  .game-layout,
  .bottom-panels {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 16px;
  }

  .app {
    padding: 10px;
  }

  .game-header,
  .result-header,
  .toolbar,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .game-header,
  .result-header {
    display: grid;
  }

  .dice-panel {
    grid-template-columns: 68px 1fr;
  }

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

  .space {
    min-height: 120px;
  }

  .name-row {
    grid-template-columns: 74px 1fr;
  }

  .online-actions {
    grid-template-columns: 1fr;
  }

  .online-game-controls {
    grid-template-columns: 1fr;
  }
}
