:root {
  color-scheme: light;
  --spectral-1: #D53E4F;
  --spectral-2: #F46D43;
  --spectral-3: #FDAE61;
  --spectral-4: #FEE08B;
  --spectral-5: #FFFFBF;
  --spectral-6: #E6F598;
  --spectral-7: #ABDDA4;
  --spectral-8: #66C2A5;
  --spectral-9: #3288BD;
  --paper: #F6F1E8;
  --paper-deep: #EDE3D3;
  --paper-light: #FFFCF5;
  --ink: #332F2A;
  --ink-soft: #6E6256;
  --border: #C8BCA9;
  --border-strong: #A9957D;
  --accent: #9B3A2A;
  --shadow: rgba(68, 51, 35, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 0;
  min-height: 100%;
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  overflow-x: hidden;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.72), transparent 27rem),
    repeating-linear-gradient(115deg, rgba(122, 94, 64, 0.025) 0 1px, transparent 1px 9px),
    linear-gradient(155deg, var(--paper-light), var(--paper) 48%, var(--paper-deep));
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button {
  min-height: 44px;
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 3px solid var(--spectral-9);
  outline-offset: 3px;
}

button:disabled {
  cursor: not-allowed;
  color: #655E55;
}

#game-root {
  width: 100%;
  min-width: 0;
}

#game-root:focus-visible {
  outline: 3px solid var(--spectral-9);
  outline-offset: 4px;
}

.loading-message {
  max-width: 720px;
  margin: 20vh auto 0;
  color: var(--ink-soft);
  text-align: center;
}

.game-shell {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: 8px;
}

.game-content {
  display: grid;
  min-width: 0;
  gap: 14px;
}

.card,
.plate-strip,
.state-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 252, 245, 0.88);
  box-shadow: 0 8px 24px var(--shadow);
}

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(254, 224, 139, 0.22)),
    var(--paper-light);
  box-shadow: 0 10px 28px var(--shadow);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.18em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 8vw, 2.35rem);
  line-height: 1.12;
  letter-spacing: 0.02em;
}

.header-stats {
  display: grid;
  flex: none;
  gap: 2px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 650;
  text-align: right;
}

.row,
.plate-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.experience {
  padding: 14px 16px 16px;
}

.experience .row {
  margin-bottom: 9px;
  font-size: 0.88rem;
  font-weight: 700;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #DFD5C6;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--spectral-2), var(--spectral-4));
  transition: width 180ms ease-out;
}

.plate-strip {
  min-width: 0;
  padding: 13px;
}

.plate-summary {
  padding: 0 3px 9px;
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.plate-track {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  min-width: 0;
  overflow-x: auto;
  padding: 3px 3px 8px;
  overscroll-behavior-inline: contain;
  scrollbar-color: var(--border-strong) transparent;
  -webkit-overflow-scrolling: touch;
}

.plate-dish {
  flex: none;
  width: 48px;
}

.empty {
  margin: 3px 0 0;
  color: var(--ink-soft);
  font-size: 0.88rem;
}

.board-head {
  align-items: flex-start;
  padding: 13px 15px;
}

.section-title,
.terminal-title {
  margin: 0;
  font-size: 1.08rem;
}

.board-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 2px 10px;
  color: var(--ink-soft);
  font-size: 0.72rem;
  font-weight: 650;
}

.board-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  gap: clamp(4px, 1.6vw, 9px);
}

.dish-tile {
  display: grid;
  aspect-ratio: 1;
  min-width: 0;
  place-items: center;
  border: 1px solid rgba(51, 47, 42, 0.28);
  border-radius: clamp(8px, 3vw, 14px);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.48), 0 3px 7px rgba(51, 47, 42, 0.13);
  font-size: clamp(1rem, 6vw, 1.8rem);
  font-weight: 850;
  line-height: 1;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

button.dish-tile {
  cursor: pointer;
}

.dish-tile.selected {
  outline: 3px solid var(--ink);
  outline-offset: 2px;
  box-shadow: 0 7px 16px rgba(51, 47, 42, 0.28);
  transform: scale(1.055);
}

.dish-tile.disabled,
.dish-tile:disabled {
  opacity: 0.58;
  filter: saturate(0.72);
}

.dish-placeholder {
  border-style: dashed;
  background: rgba(200, 188, 169, 0.2);
  box-shadow: none;
}

.selection-summary,
.action-hints {
  border-left: 4px solid var(--spectral-9);
  border-radius: 8px;
  background: rgba(50, 136, 189, 0.09);
  color: var(--ink-soft);
}

.selection-summary {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 4px 10px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 650;
}

.action-hints {
  padding: 8px 12px;
  font-size: 0.78rem;
}

.action-hints p {
  margin: 3px 0;
}

.game-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  position: sticky;
  bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 5;
  padding: 8px;
  border: 1px solid rgba(169, 149, 125, 0.78);
  border-radius: 15px;
  background: rgba(246, 241, 232, 0.94);
  box-shadow: 0 8px 24px rgba(51, 47, 42, 0.2);
  backdrop-filter: blur(10px);
}

.action-button,
.primary,
.page-tools button {
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  background: var(--paper-light);
  font-size: 0.86rem;
  font-weight: 750;
  cursor: pointer;
}

.action-button:not(:disabled):active,
.primary:not(:disabled):active,
.page-tools button:not(:disabled):active {
  transform: translateY(1px);
}

.action-button.primary,
.primary {
  border-color: #762D22;
  background: linear-gradient(160deg, #B94A38, #8D3024);
  color: #FFFFFF;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.2), 0 4px 10px rgba(118, 45, 34, 0.25);
}

.action-button:disabled,
.primary:disabled {
  border-color: var(--border);
  background: #DED4C6;
  color: #675F56;
  box-shadow: none;
  opacity: 1;
}

.terminal-hint {
  margin: -2px 0 0;
  color: var(--ink-soft);
  font-size: 0.75rem;
  text-align: center;
}

.ready-block,
.state-card {
  padding: clamp(24px, 8vw, 54px) 18px;
  text-align: center;
}

.ready-block .primary {
  width: min(100%, 280px);
  margin-top: 8px;
}

.muted {
  margin: 9px 0 16px;
  color: var(--ink-soft);
}

.page-tools {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 2px 0;
}

.page-tools button {
  padding-inline: 16px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.reset-button {
  text-decoration: underline;
  text-decoration-color: rgba(155, 58, 42, 0.42);
  text-underline-offset: 3px;
}

.modal-root:empty {
  display: none;
}

.settlement-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow-y: auto;
  background: rgba(36, 29, 23, 0.68);
  backdrop-filter: blur(4px);
}

.settlement-modal {
  width: min(100%, 440px);
  max-width: 440px;
  max-height: min(720px, 100%);
  overflow-y: auto;
  padding: clamp(20px, 6vw, 30px);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.84), rgba(254, 224, 139, 0.13)),
    var(--paper-light);
  box-shadow: 0 24px 70px rgba(20, 15, 12, 0.4);
}

.settlement-modal h2 {
  margin-bottom: 16px;
  font-size: clamp(1.5rem, 7vw, 2rem);
}

.settlement-revenue {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 15px;
  padding: 13px;
  border-block: 1px solid var(--border);
}

.settlement-revenue strong {
  color: var(--accent);
  font-size: 1.75rem;
}

.settlement-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  margin: 0 0 18px;
}

.settlement-details div {
  min-width: 0;
  padding: 10px;
  border-radius: 10px;
  background: rgba(237, 227, 211, 0.58);
}

.settlement-details dt {
  color: var(--ink-soft);
  font-size: 0.72rem;
}

.settlement-details dd {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
}

.settlement-modal > .primary {
  width: 100%;
}

.toast-region {
  position: fixed;
  left: 50%;
  bottom: max(82px, calc(env(safe-area-inset-bottom) + 68px));
  z-index: 40;
  width: max-content;
  max-width: min(88vw, 420px);
  padding: 10px 15px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(51, 47, 42, 0.94);
  color: #FFFFFF;
  font-size: 0.84rem;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 140ms ease, transform 140ms ease;
}

.toast-region.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.dish--removing {
  animation: dish-removing 106ms ease-in forwards;
}

.dish--falling {
  animation: dish-falling 214ms cubic-bezier(0.2, 0.75, 0.3, 1) both;
}

.dish--spawning {
  animation: dish-spawning 214ms cubic-bezier(0.2, 0.75, 0.3, 1) both;
}

@keyframes dish-removing {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.72);
  }
}

@keyframes dish-falling {
  from {
    opacity: 0.55;
    transform: translateY(-18%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes dish-spawning {
  from {
    opacity: 0;
    transform: scale(0.62);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (min-width: 721px) {
  body {
    padding-top: max(28px, env(safe-area-inset-top));
    padding-bottom: max(36px, env(safe-area-inset-bottom));
  }

  .game-content {
    gap: 18px;
  }

  .game-header {
    padding: 22px 24px;
  }

  .game-actions {
    position: static;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
  }

  .game-actions button {
    min-height: 50px;
  }

  .toast-region {
    bottom: 30px;
  }
}

@media (max-width: 360px) {
  body {
    padding-right: max(8px, env(safe-area-inset-right));
    padding-left: max(8px, env(safe-area-inset-left));
  }

  .game-header {
    align-items: flex-start;
    padding: 14px;
  }

  .header-stats {
    font-size: 0.72rem;
  }

  .board-head {
    display: block;
  }

  .board-meta {
    justify-content: flex-start;
    margin-top: 5px;
  }

  .game-actions {
    gap: 4px;
    padding: 6px;
  }

  .action-button {
    padding-inline: 3px;
    font-size: 0.74rem;
  }

  .settlement-details {
    gap: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html,
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
