:root {
  color: #283237;
  background: #efe8d9;
  font-family: Nunito, system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 14% 17%, rgba(255,255,255,.55) 0 1px, transparent 1.5px) 0 0 / 13px 13px,
    linear-gradient(115deg, #f7f2e8, #e9e1d0);
}

.game-shell { width: min(1044px, calc(100% - 36px)); margin: 0 auto; padding: max(22px, env(safe-area-inset-top)) 0 max(38px, env(safe-area-inset-bottom)); }
.masthead { text-align: center; margin: 0 auto 28px; }
.eyebrow { color: #9a5b39; font-family: "DM Mono", monospace; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.eyebrow span { display: inline-block; width: 22px; height: 1px; margin: 0 8px 3px 0; background: #bd7a4f; }
h1 { margin: 7px 0 5px; color: #27343a; font-family: Fraunces, Georgia, serif; font-size: clamp(38px, 6vw, 61px); letter-spacing: -.055em; line-height: 1; }
h1 i { color: #bb704a; font-size: .72em; font-weight: 600; }
.intro { margin: 14px auto 0; color: #65706f; font-size: 16px; line-height: 1.5; white-space: nowrap; }

.play-area { display: grid; grid-template-columns: minmax(0, 1000px); justify-content: center; }
#game { display: grid; grid-template-columns: minmax(0, 700px) 300px; width: 100%; min-height: 500px; overflow: hidden; border: 1px solid #d2c8b8; border-radius: 18px; background: #fdfaf2; box-shadow: 0 15px 40px rgba(82, 65, 42, .11), 0 2px 5px rgba(82,65,42,.08); }
#game-canvas { min-width: 0; }
#game-canvas canvas { display: block; width: 100% !important; height: auto !important; touch-action: pan-y pinch-zoom !important; }
.action-panel { display: flex; align-self: stretch; flex-direction: column; justify-content: flex-start; padding: 24px 18px; border-left: 1px solid #d9cdbb; background: rgba(255,252,245,.65); }
.mode-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 4px; border-radius: 10px; background: #eee6d9; }
.mode-button { padding: 8px 4px; border-radius: 7px; background: transparent; color: #77766e; font-size: 11px; }
.mode-button.selected { background: #fffdf7; box-shadow: 0 1px 3px rgba(61, 53, 43, .13); color: #386a65; }
.mode-summary { min-height: 51px; margin: 11px 3px 3px; color: #74766e; font-size: 12px; font-weight: 700; line-height: 1.4; text-align: center; }
.controls { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 23px; }
.action-panel .controls { flex-direction: column; gap: 10px; margin: 0; }
.action-panel button { width: 100%; }
.primary-actions { display: flex; width: 100%; gap: 10px; }
.primary-actions .primary { flex: 1; white-space: nowrap; }
.primary-actions button { width: auto; }
button { border: 0; font: 800 14px Nunito, sans-serif; cursor: pointer; transition: transform .15s ease, filter .15s ease; }
button:hover { filter: brightness(1.04); transform: translateY(-1px); }
button:active { transform: translateY(1px); }
button:disabled { cursor: default; filter: none; opacity: .48; transform: none; }
.primary { padding: 13px 19px 13px 22px; border-radius: 9px; background: #416e68; box-shadow: 0 3px 0 #284b48; color: #fffdf7; }
.primary span { margin-left: 9px; font-size: 19px; line-height: 0; }
.secondary { padding: 12px 17px; border: 1px solid #cfc3b2; border-radius: 9px; background: #fbf7ed; color: #69706b; }
.text-button { padding: 10px 4px; background: transparent; color: #a15f3e; text-decoration: underline; text-underline-offset: 3px; }
.status { min-height: 16px; margin: 0 0 1px; color: #74766e; font-size: 11px; font-weight: 700; line-height: 1.35; text-align: center; }
.status.success { color: #326b55; }
.status.error { color: #a55045; }
.journal-button { margin-top: 8px; padding: 10px 4px; background: transparent; color: #65706f; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
.mode-button, .primary, .secondary, .text-button, .journal-button { min-height: 40px; }
.journal-dialog { width: min(440px, calc(100% - 32px)); max-height: min(640px, calc(100vh - 32px)); padding: 24px; overflow: auto; border: 1px solid #d2c8b8; border-radius: 16px; background: #fdfaf2; box-shadow: 0 24px 80px rgba(45, 37, 27, .28); color: #283237; }
.journal-dialog::backdrop { background: rgba(42, 48, 45, .38); backdrop-filter: blur(2px); }
.journal-heading { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.journal-heading .eyebrow { margin: 0; font-size: 10px; }
.journal-heading h2 { margin: 5px 0 0; font-family: Fraunces, Georgia, serif; font-size: 29px; letter-spacing: -.04em; }
.dialog-close { width: 34px; height: 34px; border: 1px solid #d7cabb; border-radius: 50%; background: #fffaf0; color: #6f706a; font-size: 25px; font-weight: 400; line-height: 1; }
.journal-copy { margin: 18px 0 12px; color: #73756e; font-size: 14px; }
.journal-list { display: grid; gap: 8px; }
.journal-entry { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px; border: 1px solid #ded3c3; border-radius: 10px; background: #fffdf7; color: #42524f; text-align: left; }
.journal-entry span { font-size: 14px; }
.journal-entry small { color: #8a897f; font-family: "DM Mono", monospace; font-size: 10px; white-space: nowrap; }
.empty-journal { padding: 28px 8px; color: #85847a; text-align: center; }

@media (max-width: 900px) { .play-area { grid-template-columns: 1fr; } #game { grid-template-columns: 1fr; } .action-panel { border-top: 1px solid #d9cdbb; border-left: 0; } }
@media (max-width: 600px) {
  html, body { min-height: 100%; overflow-y: auto; }
  body { -webkit-overflow-scrolling: touch; }
  .game-shell { width: 100%; min-height: 100dvh; padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left)); }
  #game { min-height: 0; overflow: visible; border-radius: 14px; }
  .action-panel { gap: 3px; padding: 8px 12px; }
  .mode-picker { gap: 4px; }
  .mode-button { min-height: 40px; padding: 7px 3px; font-size: 12px; }
  .mode-summary { display: none; }
  .action-panel .controls { gap: 4px; }
  .status { min-height: 17px; margin: 1px 0; font-size: 11px; }
  .primary-actions { gap: 8px; }
  .primary, .secondary { min-height: 42px; padding: 10px 14px; }
  .text-button, .journal-button { min-height: 32px; padding: 6px 4px; font-size: 12px; }
  .journal-button { margin-top: 0; }
  .action-panel #next-button:disabled { display: none; }
  .journal-dialog { width: min(440px, calc(100% - 20px)); max-height: calc(100dvh - 20px); padding: 20px; }
}
