:root {
  color-scheme: light;
  --main: #009fb0;
  --left: #e73467;
  --right: #00913f;
  --ink: #5a2600;
  --accent: #ffd900;
  --paper: #f8f3e7;
  --paper-deep: #ffe98a;
  --muted: #76594b;
  --left-soft: #fde7ef;
  --right-soft: #e2f3e9;
  --white: #fffdf7;
  --shadow: 0 18px 60px rgba(90, 38, 0, 0.2);
  font-family: "Avenir Next", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button { font: inherit; }
button:focus-visible { outline: 4px solid rgba(90, 38, 0, 0.24); outline-offset: 3px; }
[hidden] { display: none !important; }

.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;
}

.language-switcher { display: block; }
.home-language { position: absolute; z-index: 4; top: max(22px, env(safe-area-inset-top)); right: max(24px, env(safe-area-inset-right)); }
.language-select {
  min-height: 40px;
  padding: 0 34px 0 14px;
  border: 1px solid rgba(90, 38, 0, 0.22);
  border-radius: 12px;
  background: rgba(255, 253, 247, 0.95);
  color: var(--ink);
  font: 800 14px/1 "Avenir Next", "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
  cursor: pointer;
}
.language-select:focus-visible { outline: 4px solid rgba(255, 217, 0, 0.7); outline-offset: 2px; }

.app-shell { width: 100%; height: 100%; }

.home-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 217, 0, 0.78) 0 11%, transparent 12%),
    radial-gradient(circle at 86% 78%, rgba(0, 145, 63, 0.55) 0 14%, transparent 15%),
    linear-gradient(135deg, #009fb0, #008b9b);
}

.home-card {
  width: min(720px, 82vw);
  padding: clamp(28px, 5vh, 54px) clamp(40px, 7vw, 78px);
  text-align: center;
  background: rgba(255, 253, 247, 0.96);
  border: 2px solid rgba(90, 38, 0, 0.12);
  border-radius: 38px;
  box-shadow: var(--shadow);
}

.eyebrow { margin: 0 0 8px; color: var(--left); font-size: 15px; font-weight: 800; letter-spacing: 0.18em; }
h1 { margin: 0; font-size: clamp(54px, 8vw, 92px); line-height: 1; letter-spacing: -0.07em; }
html[lang="ja"] h1 { font-size: clamp(48px, 5vw, 68px); line-height: 1.12; letter-spacing: -0.05em; }
.home-lead { margin: 22px 0 26px; color: var(--muted); font-size: clamp(18px, 2.2vw, 24px); line-height: 1.65; }

.how-to-play { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 0 auto 28px; }
.how-to-play div { padding: 14px 8px; border-radius: 18px; background: var(--paper); }
.how-to-play span { display: grid; place-items: center; width: 28px; height: 28px; margin: 0 auto 6px; border-radius: 50%; background: var(--ink); color: var(--accent); font-weight: 800; }
.how-to-play p { margin: 0; font-size: 15px; font-weight: 700; }

.primary-button, .secondary-button, .danger-button {
  min-height: 54px;
  padding: 0 30px;
  border: 0;
  border-radius: 18px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button { background: var(--accent); color: var(--ink); box-shadow: 0 8px 0 var(--ink); }
.primary-button:active { transform: translateY(4px); box-shadow: 0 4px 0 var(--ink); }
.home-card > .primary-button { min-width: 240px; font-size: 21px; }
.device-tip { margin: 20px 0 0; color: var(--muted); font-size: 13px; }

.game-screen { height: 100%; display: grid; grid-template-rows: 64px minmax(0, 1fr) 76px; background: var(--white); }
.score-bar { display: flex; align-items: center; gap: 20px; padding: 0 max(20px, env(safe-area-inset-right)) 0 max(28px, env(safe-area-inset-left)); border-bottom: 1px solid rgba(90, 38, 0, 0.18); background: var(--paper); }
.brand-mini { margin-right: auto; font-size: 21px; font-weight: 900; letter-spacing: -0.04em; }
.game-stat { display: flex; align-items: baseline; gap: 5px; color: var(--muted); font-size: 14px; }
.game-stat strong { color: var(--ink); font-size: 24px; }
.game-stat.score strong { color: var(--left); }
.level-pill { padding: 8px 15px; border-radius: 999px; background: var(--ink); color: white; font-size: 13px; }
.game-language .language-select { min-height: 36px; background: var(--white); }

.board { position: relative; min-height: 0; display: grid; grid-template-columns: 1fr 18px 1fr; overflow: hidden; touch-action: none; }
.draw-zone { position: relative; min-width: 0; overflow: hidden; }
.left-zone { background: linear-gradient(135deg, var(--white), var(--left-soft)); }
.right-zone { background: linear-gradient(225deg, var(--white), var(--right-soft)); }
.draw-zone canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.zone-heading { position: absolute; z-index: 2; top: 16px; left: 50%; display: flex; align-items: center; gap: 8px; transform: translateX(-50%); color: var(--muted); font-size: 15px; font-weight: 800; pointer-events: none; }
.hand-dot { width: 10px; height: 10px; border-radius: 50%; }
.left-dot { background: var(--left); }
.right-dot { background: var(--right); }
.center-divider { display: grid; place-items: center; background: var(--paper); }
.center-divider span { width: 2px; height: 86%; border-radius: 2px; background: repeating-linear-gradient(to bottom, var(--accent) 0 8px, transparent 8px 16px); }

.side-result { position: absolute; z-index: 3; right: 18px; bottom: 18px; min-width: 84px; min-height: 32px; display: grid; place-items: center; border-radius: 999px; font-size: 14px; font-weight: 800; pointer-events: none; }
.side-result.good { background: #dff4e7; color: var(--right); }
.side-result.bad { background: #fde0e9; color: var(--left); }

.round-message { position: absolute; z-index: 5; top: 18px; left: 50%; max-width: 70%; padding: 11px 22px; transform: translateX(-50%) translateY(-16px); border-radius: 999px; background: var(--ink); color: white; font-size: 15px; font-weight: 800; opacity: 0; pointer-events: none; transition: 180ms ease; }
.round-message.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.round-message.success { background: var(--right); }
.round-message.error { background: var(--left); }

.countdown { position: absolute; z-index: 7; inset: 0; display: grid; place-items: center; background: rgba(255, 253, 247, 0.52); color: var(--ink); font-size: clamp(92px, 18vw, 180px); font-weight: 900; backdrop-filter: blur(2px); }

.control-bar { display: flex; align-items: center; padding: 0 max(28px, env(safe-area-inset-right)) max(0px, env(safe-area-inset-bottom)) max(28px, env(safe-area-inset-left)); border-top: 1px solid rgba(90, 38, 0, 0.18); background: var(--paper); }
.control-bar p { margin: 0 auto 0 0; color: var(--muted); font-size: 15px; font-weight: 700; }
.controls { display: flex; gap: 12px; }
.secondary-button, .danger-button { min-height: 46px; padding: 0 24px; background: var(--white); border: 2px solid rgba(90, 38, 0, 0.22); color: var(--ink); }
.danger-button { border-color: rgba(231, 52, 103, 0.46); color: var(--left); }
.danger-button.solid { background: var(--left); border-color: var(--left); color: white; }

.modal-backdrop { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(90, 38, 0, 0.64); backdrop-filter: blur(8px); }
.modal { width: min(440px, 90vw); padding: 34px; text-align: center; background: var(--white); border-radius: 30px; box-shadow: var(--shadow); }
.modal-icon { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 16px; border-radius: 20px; background: var(--paper-deep); font-size: 25px; font-weight: 900; }
.stop-icon { color: var(--left); }
.modal h2 { margin: 0 0 10px; font-size: 30px; }
.modal p { margin: 0 0 24px; color: var(--muted); line-height: 1.6; }
.modal > .primary-button { width: 100%; }
.text-button { margin-top: 22px; border: 0; background: none; color: var(--left); font-weight: 800; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.final-score { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 20px 0 8px; }
.final-score strong { color: var(--left); font-size: 76px; line-height: 1; }
.final-score span { font-weight: 800; }
.summary-modal small { color: var(--muted); }

.portrait-warning { display: none; }

@media (orientation: portrait) and (max-width: 900px) {
  .app-shell, .modal-backdrop { display: none !important; }
  .portrait-warning { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 40px; text-align: center; background: var(--paper); }
  .portrait-warning .rotate-icon { font-size: 72px; color: var(--right); }
  .portrait-warning strong { font-size: 28px; }
  .portrait-warning span { color: var(--muted); }
}

@media (max-height: 600px) {
  .game-screen { grid-template-rows: 54px minmax(0, 1fr) 64px; }
  .score-bar { gap: 16px; }
  .language-select { min-height: 36px; }
  .home-card { padding-top: 24px; padding-bottom: 24px; }
  .home-lead { margin: 12px 0 16px; }
  .how-to-play { margin-bottom: 20px; }
}

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