:root {
  --paper: #f6f1e4;
  --ink: #2c2416;
  --muted: #6d6256;
  --line: #d7e3f4;
  --margin: #e7a8a8;
  --blue: #1d4ed8;
  --red: #c62828;
  --card: rgba(246, 241, 228, 0.94);
  --stroke: #e4d3b8;
  --shadow: 0 18px 50px rgba(70, 45, 20, 0.16);
  color-scheme: light;
  font-family: "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background: #e7dcc8;
  min-height: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.screen {
  min-height: 100dvh;
  display: none;
  background: #efe4d0 center/cover no-repeat;
}
.screen.active { display: flex; }
#screen-menu.active, #screen-results.active {
  align-items: center;
  justify-content: center;
  padding: 48px 16px;
}
.hidden { display: none !important; }

.paper {
  background: var(--card);
  border: 1px solid var(--stroke);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.menu {
  align-items: center;
  justify-content: center;
  padding: 24px 16px 40px;
}
.menu-card {
  width: min(460px, 100%);
  padding: 28px 28px 24px;
  text-align: center;
  position: relative;
}
.menu-card::before {
  content: "";
  position: absolute;
  left: 28px;
  top: 18px;
  bottom: 18px;
  width: 2px;
  background: var(--margin);
  border-radius: 2px;
}
.mascot-frame {
  width: 168px;
  height: 168px;
  margin: -78px auto 8px;
  border-radius: 50%;
  overflow: hidden;
  background: #f3ecdf;
  border: 4px solid #fff;
  box-shadow: 0 10px 24px rgba(70, 45, 20, 0.18);
}
.mascot-frame img { width: 100%; height: 100%; object-fit: cover; object-position: center 18%; }
h1 {
  font-family: Georgia, "Iowan Old Style", serif;
  font-weight: 700;
  font-size: 56px;
  margin: 8px 0 0;
  letter-spacing: -0.03em;
}
.lede { color: var(--muted); margin: 4px 0 18px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.btn {
  border: 1px solid #ddc9a8;
  background: #fffaf2;
  border-radius: 999px;
  padding: 12px 18px;
  box-shadow: inset 0 1px 0 #fff;
}
.btn:hover { background: #fff; }
.btn.primary { background: #2c2416; color: #f6f1e4; border-color: #2c2416; }
.btn.primary:hover { background: #433628; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn:disabled { opacity: 0.45; cursor: default; }
.icon-row { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid #ddc9a8;
  background: #fffaf2;
}

.sheet {
  width: min(860px, 100%);
  margin: 24px auto;
  padding: 22px 22px 28px;
}
.sheet h2 { font-family: Georgia, serif; margin: 0 0 8px; }
.sheet-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.groups { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 16px; }
fieldset {
  border: 1px solid var(--stroke);
  border-radius: 18px;
  margin: 0;
  padding: 12px 14px 14px;
  background: rgba(255, 250, 242, 0.65);
}
legend { padding: 0 6px; color: var(--muted); }
label { display: flex; justify-content: space-between; gap: 10px; align-items: center; margin: 8px 0; font-size: 15px; }
label.block { display: block; }
select, input[type="range"] { width: 150px; }
.about-copy { line-height: 1.5; }
.about-copy p { margin: 0 0 10px; }

#screen-settings.active, #screen-about.active { display: block; overflow: auto; }
#screen-game {
  height: 100dvh;
  min-height: 100dvh;
  display: none;
  grid-template-rows: auto 1fr auto;
}
#screen-game.active { display: grid; }
.topbar, .toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(246, 241, 228, 0.92);
  border-bottom: 1px solid var(--stroke);
}
.toolbar { border-bottom: 0; border-top: 1px solid var(--stroke); flex-wrap: wrap; }
.topbar { justify-content: space-between; }
.status-block { text-align: center; flex: 1; }
#status { font-weight: 650; }
#scoreline, #move-meta { color: var(--muted); font-size: 13px; }
.thinking::after { content: "…"; animation: dots 1s steps(3, end) infinite; }
@keyframes dots { 0% { content: ""; } 33% { content: "."; } 66% { content: ".."; } }
#board-wrap { position: relative; min-height: 0; touch-action: none; cursor: crosshair; }
#board, #fx { position: absolute; inset: 0; width: 100%; height: 100%; }
#fx { pointer-events: none; }
#fx.live { pointer-events: auto; }
#hover-tip {
  position: absolute;
  left: 12px;
  bottom: 10px;
  margin: 0;
  padding: 6px 10px;
  background: rgba(44, 36, 22, 0.88);
  color: #f6f1e4;
  border-radius: 999px;
  font-size: 13px;
}
.log-panel {
  position: absolute;
  top: 8px;
  right: 8px;
  width: min(280px, calc(100% - 16px));
  max-height: 46%;
  overflow: auto;
  padding: 10px 12px;
  z-index: 2;
}
.log-panel ol { margin: 8px 0 0; padding-left: 18px; }
.log-panel li { margin: 4px 0; font-size: 14px; }

#screen-results { align-items: center; justify-content: center; padding: 20px 16px; }
.result-card { width: min(520px, 100%); padding: 22px; text-align: center; }
.result-card h2 { font-family: Georgia, serif; font-size: 40px; margin: 8px 0; }
.stats { text-align: left; margin: 12px 0 16px; }
.stats div { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed #e4d3b8; }

#coach, #modal, #rules {
  border: 0;
  padding: 0;
  background: transparent;
  z-index: 40;
}
#coach {
  width: min(560px, calc(100% - 24px));
}
#coach::backdrop, #modal::backdrop, #rules::backdrop { background: rgba(36, 26, 16, 0.55); }
body.dim::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(36, 26, 16, 0.48);
  z-index: 30;
}
.coach-card { padding: 18px 18px 16px; }
.coach-top { display: flex; gap: 12px; align-items: center; }
.coach-top img { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; object-position: center 18%; background: #f3ecdf; }
#coach-board { width: 100%; height: 240px; border-radius: 16px; background: #f7f2e6; margin-top: 10px; touch-action: none; }
.coach-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.dots { display: flex; gap: 6px; justify-content: center; margin-top: 8px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: #ddc9a8; display: block; }
.dots i.on { background: #2c2416; }

#modal { border: 0; padding: 0; background: transparent; }
#modal::backdrop { background: rgba(44, 36, 22, 0.4); }
.modal-card { width: min(420px, calc(100vw - 32px)); padding: 18px; }
.modal-card h3 { font-family: Georgia, serif; margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: #2c2416;
  color: #f6f1e4;
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 5;
  max-width: min(520px, calc(100% - 24px));
}

#file-banner {
  background: #fff4d6;
  color: #2c2416;
  padding: 8px 12px;
  text-align: center;
}

@media (max-width: 720px) {
  h1 { font-size: 44px; }
  .toolbar .btn { padding: 10px 12px; }
  .mascot-frame { width: 132px; height: 132px; margin-top: -64px; }
}
#boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e7dcc8;
  transition: opacity 0.28s ease;
}
#boot.done { opacity: 0; pointer-events: none; }
.boot-card { width: min(420px, calc(100% - 48px)); }
.boot-title {
  margin: 0 0 18px;
  text-align: center;
  font-family: Georgia, "Iowan Old Style", serif;
  font-size: 48px;
  font-weight: 700;
}
.boot-track {
  height: 8px;
  border-radius: 999px;
  background: #f6f1e4;
  border: 1px solid #e4d3b8;
  overflow: hidden;
}
#boot-bar {
  display: block;
  height: 100%;
  width: 6%;
  border-radius: inherit;
  background: #2c2416;
  animation: boot-creep 1.8s ease-out forwards;
}
@keyframes boot-creep { to { width: 38%; } }
.boot-label {
  margin: 12px 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .thinking::after { animation: none; }
  #boot { transition: none; }
  #boot-bar { animation: none; }
}
