:root {
  color-scheme: light;
  --paper: #f7efe0;
  --paper-bright: #fffaf0;
  --ink: #173c3d;
  --muted: #607675;
  --river: #176d70;
  --river-deep: #103f49;
  --sun: #f4c978;
  --coral: #d96950;
  --line: #e4d9c4;
  --shadow: 0 18px 50px rgba(35, 55, 47, 0.09);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 86% 4%, rgba(244, 201, 120, 0.23), transparent 31rem),
    radial-gradient(ellipse at 2% 46%, rgba(39, 137, 132, 0.08), transparent 30rem),
    var(--paper);
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
a { color: #145e61; text-underline-offset: 0.18em; }
a:hover { color: #9d4c3b; }
button:focus-visible, a:focus-visible, canvas:focus-visible {
  outline: 3px solid #d96950;
  outline-offset: 3px;
}

.page-shell {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding-top: 22px;
  padding-right: max(18px, env(safe-area-inset-right));
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  padding-left: max(18px, env(safe-area-inset-left));
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 42px;
  margin-bottom: clamp(28px, 5vw, 60px);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); text-decoration: none; }
.brand-name { font-size: 13px; letter-spacing: 0.18em; font-weight: 750; }
.brand-name b { color: var(--river); }
.brand-mark { display: inline-flex; flex-direction: column; justify-content: center; gap: 3px; width: 28px; height: 24px; }
.brand-mark span { display: block; width: 26px; height: 5px; border: 2px solid var(--river); border-radius: 100%; transform: skewX(-15deg); }
.brand-mark span:nth-child(2) { width: 21px; margin-left: 4px; border-color: #d96950; }
.brand-mark span:nth-child(3) { width: 16px; margin-left: 8px; border-color: #d8a24d; }
.header-note { display: flex; gap: 9px; align-items: center; margin: 0; color: var(--muted); font-size: 13px; letter-spacing: 0.015em; }
.sun-dot { width: 8px; height: 8px; border-radius: 50%; background: #dca34c; box-shadow: 0 0 0 4px rgba(220, 163, 76, 0.17); }

.intro-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  margin: 0 0 28px;
}
.kicker, .micro-label {
  margin: 0;
  color: #53706b;
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.16em;
  font-weight: 800;
}
.intro-row h1 {
  margin: 8px 0 7px;
  color: #153c3c;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, 5.2vw, 66px);
  line-height: 0.98;
  font-weight: 500;
  letter-spacing: -0.045em;
}
.intro-row h1 em { color: #c8624c; font-weight: 500; }
.intro-copy { max-width: 600px; margin: 13px 0 0; color: #526b69; font-size: 15px; line-height: 1.65; }
.setting-chip {
  display: flex;
  align-items: center;
  gap: 11px;
  flex: 0 0 auto;
  padding: 11px 14px;
  margin-bottom: 3px;
  background: rgba(255, 250, 240, 0.74);
  border: 1px solid rgba(228, 217, 196, 0.8);
  border-radius: 15px;
}
.setting-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #80552c; background: #f2d394; font-size: 21px; }
.setting-chip strong, .setting-chip small { display: block; }
.setting-chip strong { font-size: 12px; line-height: 1.3; }
.setting-chip small { margin-top: 3px; color: var(--muted); font-size: 11px; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.46fr) minmax(310px, 0.78fr); gap: 20px; align-items: stretch; }
.board-card, .route-card {
  min-width: 0;
  background: rgba(255, 250, 240, 0.92);
  border: 1px solid rgba(226, 215, 195, 0.88);
  border-radius: 23px;
  box-shadow: var(--shadow);
}
.board-card { padding: 15px; }
.board-topline { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 1px 3px 12px; }
.board-label { display: inline-flex; align-items: center; gap: 8px; color: #486865; font-size: 10px; letter-spacing: 0.14em; font-weight: 800; }
.pulse-dot { width: 7px; height: 7px; border-radius: 50%; background: #df8b62; box-shadow: 0 0 0 4px rgba(223, 139, 98, 0.16); }
.move-readout { padding: 5px 10px; border-radius: 999px; color: #416562; background: #edf2e8; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border: 1px solid rgba(16, 63, 73, 0.2);
  border-radius: 16px;
  background: #103f49;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
}
#riverCanvas { display: block; width: 100%; height: 100%; outline: none; touch-action: manipulation; }
.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: safe center;
  justify-content: center;
  overflow-y: auto;
  padding: clamp(14px, 4vw, 38px);
  background: linear-gradient(135deg, rgba(11, 48, 55, 0.39), rgba(17, 69, 70, 0.55));
  backdrop-filter: blur(3px);
}
.board-overlay[hidden] { display: none; }
.overlay-card {
  width: min(100%, 440px);
  flex: 0 0 auto;
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid rgba(255,255,255,0.7);
  border-radius: 19px;
  background: rgba(255, 250, 240, 0.97);
  box-shadow: 0 16px 42px rgba(13, 44, 47, 0.28);
}
.overlay-kicker { margin: 0 0 9px; color: #a45d43; font-size: 10px; letter-spacing: 0.16em; font-weight: 800; }
.overlay-card h2 { margin: 0 0 9px; color: #183e3e; font-family: Georgia, "Times New Roman", serif; font-size: clamp(25px, 4vw, 34px); line-height: 1.08; font-weight: 500; letter-spacing: -0.02em; }
.overlay-card p:not(.overlay-kicker) { margin: 0 0 19px; color: #4f6966; font-size: 14px; line-height: 1.55; }
.button-primary, .button-secondary, .button-quiet {
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 750;
  transition: transform 120ms ease, background-color 120ms ease, box-shadow 120ms ease;
}
.button-primary { width: 100%; padding: 0 18px; color: #fffaf1; background: #176d70; box-shadow: 0 6px 14px rgba(23, 109, 112, 0.19); }
.button-primary:hover { background: #115a5f; transform: translateY(-1px); }
.button-quiet { width: 100%; margin-top: 8px; color: #5a6f69; background: transparent; border-color: #d8ddcf; }
.button-quiet:hover { background: #f2f2e8; }
.button-secondary { padding: 0 15px; color: #1f5657; background: #f3f3e8; border-color: #dce2d3; }
.button-secondary:hover:not(:disabled) { background: #e8eee1; border-color: #b9c9bb; }
.button-secondary:disabled { cursor: not-allowed; color: #788882; background: #f1eee5; border-color: #e4dfd2; opacity: 0.72; }
.button-primary:active, .button-secondary:active:not(:disabled), .dpad button:active { transform: translateY(1px); }

.board-footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 14px; padding: 13px 4px 1px; color: #5b716c; font-size: 11px; }
.board-footer span { display: inline-flex; align-items: center; gap: 6px; }
.board-footer i { display: inline-grid; place-items: center; width: 16px; height: 16px; font-style: normal; }
.legend-basket { border-radius: 50% 50% 42% 42%; background: #d59a42; box-shadow: inset 0 -4px 0 rgba(115, 70, 31, 0.2); }
.legend-dock { border-radius: 3px 3px 7px 7px; background: linear-gradient(90deg, #d96950 0 34%, #f5d69a 34% 66%, #d96950 66%); border-bottom: 3px solid #8a4d2d; }
.legend-flow { color: #176d70; font-size: 18px; font-weight: 900; }
.legend-rock { border-radius: 55% 45% 50% 40%; background: #9a7656; box-shadow: 5px 2px 0 -1px #b69770; }

.route-card { display: flex; flex-direction: column; padding: 23px; }
.route-heading { display: flex; justify-content: space-between; align-items: start; gap: 14px; }
.route-heading h2 { margin: 5px 0 0; color: #173e3f; font-family: Georgia, "Times New Roman", serif; font-size: clamp(27px, 3vw, 36px); font-weight: 500; letter-spacing: -0.025em; }
.route-stamp { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 0 0 54px; height: 54px; border: 1px solid #e2d7c2; border-radius: 50%; color: #8d6042; background: #f7ebd5; }
.route-stamp span { font-family: Georgia, "Times New Roman", serif; font-size: 22px; line-height: 1; }
.route-stamp small { margin-top: 2px; font-size: 7px; letter-spacing: 0.1em; font-weight: 800; }
.route-description { min-height: 50px; margin: 12px 0 20px; color: #526b68; font-size: 13px; line-height: 1.55; }
.route-picker { padding: 14px 0 17px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.route-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 10px; }
.route-tab { min-height: 40px; padding: 4px 7px; border: 1px solid #dce1d5; border-radius: 10px; color: #496561; background: #f6f5eb; cursor: pointer; font-size: 12px; font-weight: 750; }
.route-tab:hover:not(:disabled) { background: #edf1e5; }
.route-tab[aria-current="step"] { color: #fffaf0; background: #176d70; border-color: #176d70; }
.route-tab:disabled { color: #7e8b82; background: #f4f1e8; cursor: not-allowed; opacity: 0.62; }
.cargo-card { display: flex; align-items: center; gap: 11px; min-height: 65px; padding: 11px 12px; margin: 16px 0 14px; border: 1px solid #e9dfcc; border-radius: 14px; background: #fffaf0; }
.cargo-card.is-loaded { border-color: #d5c08c; background: #fff4d9; }
.cargo-icon { display: grid; place-items: center; flex: 0 0 38px; height: 38px; border-radius: 12px; color: #81532e; background: #f2dfb4; font-size: 23px; font-weight: 800; }
.cargo-card strong, .cargo-card small { display: block; }
.cargo-card strong { font-size: 12px; line-height: 1.4; }
.cargo-card small { margin-top: 3px; color: #6a7b72; font-size: 11px; line-height: 1.35; }
.action-row { display: grid; grid-template-columns: 0.82fr 1.18fr; gap: 8px; }

.controls-block { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 17px 0 15px; margin-top: 16px; border-top: 1px solid var(--line); }
.controls-copy p:last-child { margin: 8px 0 0; color: #345b58; font-size: 13px; line-height: 1.55; font-weight: 750; }
.controls-copy p:last-child span { color: #72827a; font-size: 12px; font-weight: 500; }
.dpad { display: grid; grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 44px); gap: 5px; flex: 0 0 auto; }
.dpad button { display: grid; place-items: center; width: 48px; height: 44px; padding: 0; border: 1px solid #d8e0d5; border-radius: 11px; color: #1d5d5e; background: #edf1e7; cursor: pointer; font-size: 22px; line-height: 1; font-weight: 750; touch-action: manipulation; }
.dpad button:hover:not(:disabled) { background: #dfeadd; border-color: #b8cbbf; }
.dpad button:disabled { color: #81918a; opacity: 0.55; cursor: not-allowed; }
.dpad-spacer { visibility: hidden; }
.rule-note, .calm-note { margin: 0; color: #536d68; font-size: 11px; line-height: 1.55; }
.rule-note { padding: 12px 13px; border-radius: 12px; background: #eaf1e7; }
.rule-note span { margin-right: 5px; color: #176d70; font-size: 15px; font-weight: 900; }
.calm-note { padding: 12px 2px 0; color: #7c7563; }
.calm-note span { margin-right: 5px; color: #bd8341; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.closing-note { display: flex; align-items: start; justify-content: space-between; gap: 20px; padding: 19px 3px 0; color: #6c7971; font-size: 11px; line-height: 1.6; }
.closing-note p { max-width: 760px; margin: 0; }
.closing-note > span { flex: 0 0 auto; color: #6c7971; font-size: 9px; letter-spacing: 0.13em; font-weight: 800; white-space: nowrap; }
.closing-note > span b { color: #cc7658; }
.footer-sun { padding-left: 3px; color: #ba874a; font-size: 12px; }

@media (max-width: 980px) {
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .route-card { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(270px, 0.9fr); column-gap: 22px; }
  .route-heading, .route-description, .route-picker, .cargo-card, .action-row { grid-column: 1; }
  .controls-block, .rule-note, .calm-note { grid-column: 2; }
  .controls-block { grid-row: 1 / span 2; align-self: center; margin: 0; padding: 0 0 14px; border-top: 0; }
  .rule-note { grid-row: 3; align-self: start; }
  .calm-note { grid-row: 4; padding-top: 10px; }
  .route-description { min-height: auto; }
}

@media (max-width: 640px) {
  .page-shell { padding-top: 16px; }
  .site-header { margin-bottom: 34px; }
  .header-note { font-size: 11px; }
  .intro-row { align-items: start; flex-direction: column; gap: 18px; margin-bottom: 20px; }
  .intro-copy { max-width: 540px; font-size: 14px; }
  .setting-chip { padding: 9px 12px; }
  .board-card { padding: 10px; border-radius: 18px; }
  .board-topline { margin: 1px 2px 9px; }
  .canvas-wrap { border-radius: 12px; }
  .board-footer { justify-content: flex-start; gap: 8px 15px; padding: 11px 3px 2px; font-size: 10px; }
  .route-card { display: flex; padding: 18px; border-radius: 18px; }
  .route-description { margin-bottom: 15px; }
  .controls-block { margin-top: 14px; padding: 15px 0 13px; border-top: 1px solid var(--line); }
  .dpad { grid-template-columns: repeat(3, 48px); grid-template-rows: repeat(3, 46px); gap: 5px; }
  .dpad button { height: 46px; }
  .closing-note { flex-direction: column; gap: 8px; padding-top: 16px; }
}

@media (max-width: 390px) {
  .page-shell { padding-inline: max(12px, env(safe-area-inset-left)); }
  .header-note { max-width: 148px; text-align: right; }
  .route-tabs { gap: 5px; }
  .route-tab { padding-inline: 3px; font-size: 11px; }
  .controls-block { align-items: start; }
  .dpad { grid-template-columns: repeat(3, 43px); grid-template-rows: repeat(3, 42px); gap: 4px; }
  .dpad button { width: 43px; height: 42px; }
  .closing-note > span { font-size: 8px; }
}

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