:root {
  color-scheme: light;
  --jade-950: #041d1a;
  --jade-900: #07332d;
  --jade-800: #0a4b40;
  --jade-600: #118e72;
  --mint: #5ce6b6;
  --red: #db3138;
  --red-dark: #8e1721;
  --gold: #f2c85b;
  --ivory: #fff9e9;
  --ink: #102821;
  --line: rgba(242, 200, 91, .38);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: #061b19; }
body {
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ivory);
  font-family: "Yu Gothic UI", "Hiragino Sans", Meiryo, sans-serif;
  font-weight: 700;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button, a { font: inherit; }
button { cursor: pointer; }

.game-shell {
  position: relative;
  width: min(100%, 560px);
  min-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px),
    radial-gradient(circle at 50% 30%, #126653 0, #07332d 42%, #041d1a 100%);
  background-size: 24px 24px, 24px 24px, auto;
  border-inline: 1px solid rgba(255,255,255,.08);
  isolation: isolate;
}

.game-shell::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: #061b19;
}

.topbar {
  position: relative;
  z-index: 2000;
  min-height: 52px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  background: rgba(4, 29, 26, .93);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 17px; font-weight: 900; }
.brand-seal { display: grid; place-items: center; width: 27px; height: 27px; color: #fff; background: var(--red); border: 2px solid var(--gold); box-shadow: 2px 2px 0 var(--red-dark); }
.top-actions { display: flex; gap: 6px; }
.icon-button { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 1px solid rgba(255,255,255,.28); border-radius: 4px; color: var(--ivory); background: rgba(255,255,255,.07); text-decoration: none; font-size: 18px; font-weight: 900; }
.icon-button:active { transform: translateY(1px); }

.screen { display: none; min-height: calc(100dvh - 52px); }
.screen.active { display: block; }

.title-screen { position: relative; overflow: hidden; }
.title-screen::before, .title-screen::after { content: ""; position: absolute; pointer-events: none; }
.title-screen::before { width: 240px; height: 240px; left: -130px; top: 14%; border: 48px solid rgba(219,49,56,.13); transform: rotate(45deg); }
.title-screen::after { width: 180px; height: 180px; right: -110px; bottom: 10%; border: 34px solid rgba(242,200,91,.1); transform: rotate(45deg); }
.title-content { position: relative; z-index: 1; min-height: calc(100dvh - 52px); padding: clamp(22px, 5vh, 48px) 22px max(24px, env(safe-area-inset-bottom)); text-align: center; }
.kicker, .result-kicker { margin: 0 0 8px; color: var(--mint); font-family: Consolas, monospace; font-size: 12px; font-weight: 900; }
.title-content h1 { margin: 0; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; font-size: clamp(46px, 14vw, 74px); line-height: .95; text-shadow: 0 4px 0 #05241f, 0 0 24px rgba(92,230,182,.25); }
.title-content h1 span { color: var(--gold); }
.title-copy { max-width: 450px; margin: 16px auto 8px; color: #d9eee7; font-size: 14px; line-height: 1.75; }
.title-tower { position: relative; width: min(90vw, 390px); height: clamp(220px, 39vh, 340px); margin: 4px auto 0; perspective: 700px; }
.demo-tile { position: absolute; width: 62px; height: 80px; display: grid; place-items: center; color: var(--ink); background: linear-gradient(145deg, #fffef7, #f0e7ca 72%); border: 2px solid #fff; border-radius: 7px; box-shadow: 0 8px 0 #b9a76d, 0 12px 16px rgba(0,0,0,.35); font-family: "Yu Mincho", serif; font-size: 31px; font-weight: 900; transform: translate(-50%, -50%) rotate(var(--r)); }
.demo-tile.red { color: #c42931; }
.demo-tile.green { color: #08705b; }
.title-record { width: min(100%, 330px); margin: -4px auto 12px; display: flex; align-items: baseline; justify-content: space-between; padding: 9px 13px; border-block: 1px solid var(--line); }
.title-record span { color: var(--gold); font-family: Consolas, monospace; font-size: 12px; }
.title-record strong { font-family: Consolas, monospace; font-size: 24px; }
.start-button { width: min(100%, 330px); min-height: 64px; border: 2px solid #fff0a9; border-radius: 5px; color: #172519; background: linear-gradient(#ffd86e, #eead32); box-shadow: 0 5px 0 #9d5a14, 0 9px 20px rgba(0,0,0,.25); }
.start-button span { display: block; font-size: 21px; font-weight: 1000; }
.start-button small { display: block; margin-top: 2px; font: 800 10px Consolas, monospace; }
.start-button:active { transform: translateY(4px); box-shadow: 0 1px 0 #9d5a14; }
.title-links, .result-actions { display: flex; justify-content: center; gap: 10px; margin-top: 15px; }
.title-links a, .title-links button, .result-actions button { min-width: 110px; padding: 9px 12px; border: 1px solid rgba(255,255,255,.3); border-radius: 4px; color: #e4f6f0; background: rgba(255,255,255,.06); text-decoration: none; font-size: 13px; }

.play-screen.active { display: flex; flex-direction: column; min-height: calc(100dvh - 52px); }
.hud { display: grid; grid-template-columns: 1.35fr 1fr 1fr; min-height: 58px; background: rgba(3,27,24,.9); border-bottom: 1px solid var(--line); }
.hud-item { display: flex; flex-direction: column; justify-content: center; padding: 7px 10px; border-right: 1px solid rgba(255,255,255,.1); }
.hud-item:last-child { border-right: 0; }
.hud-item > span { color: #a7ccc0; font: 800 9px Consolas, monospace; }
.hud-item strong { margin-top: 1px; font: 900 clamp(18px, 5vw, 24px) Consolas, monospace; white-space: nowrap; }
.combo-box strong { color: var(--gold); }
.combo-box strong small { margin-left: 5px; color: #f8f1d4; font-size: 11px; }
.time-box strong.warning { color: #ff6e70; animation: timePulse .55s steps(2) infinite; }
@keyframes timePulse { 50% { opacity: .55; } }
.combo-meter { height: 5px; background: #031b18; }
.combo-meter > div { width: 0; height: 100%; background: linear-gradient(90deg, var(--mint), var(--gold), #ff5a62); transition: width .08s linear; box-shadow: 0 0 12px rgba(242,200,91,.55); }
.status-line { min-height: 33px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 7px; padding: 5px 9px; color: #bbd8d0; background: rgba(8,51,45,.92); font-size: 10px; }
.status-line strong { color: var(--ivory); font-size: 12px; text-align: center; }
.status-line span:last-child { text-align: right; }

.board-wrap { position: relative; flex: 1 0 auto; min-height: 400px; overflow: hidden; }
.board-wrap::before { content: ""; position: absolute; inset: 10px 9px; border: 1px solid rgba(242,200,91,.18); box-shadow: inset 0 0 50px rgba(0,0,0,.25); pointer-events: none; }
.board-glow { position: absolute; left: 50%; top: 48%; width: 68%; height: 68%; transform: translate(-50%,-50%); background: radial-gradient(ellipse, rgba(92,230,182,.1), transparent 66%); pointer-events: none; }
.tile-board { position: relative; width: 100%; height: 100%; margin: 0 auto; }
.mahjong-tile { position: absolute; margin: 0; padding: 0; border: 0; border-radius: 7px; background: transparent; filter: drop-shadow(0 5px 3px rgba(0,0,0,.3)); transition: transform .12s ease, filter .12s ease, opacity .15s ease; transform: translate(calc(var(--lift-x) * 1px), calc(var(--lift-y) * 1px)); }
.mahjong-tile::before { content: ""; position: absolute; inset: 5px -2px -7px 4px; border-radius: 7px; background: linear-gradient(145deg, #cdbf8c, #8e7b45); box-shadow: 1px 2px 0 #6d5b2d; }
.tile-face { position: absolute; inset: 0; overflow: visible; border: 0; border-radius: 7px; background: transparent; box-shadow: none; }
.tile-face::after { display: none; }
.mahjong-tile img { position: relative; z-index: 1; display: block; width: 100%; height: 100%; object-fit: fill; user-select: none; pointer-events: none; filter: saturate(1.08) contrast(1.06); }
.mahjong-tile.blocked { opacity: .78; filter: saturate(.78) brightness(.87) drop-shadow(0 4px 2px rgba(0,0,0,.26)); }
.mahjong-tile.free { cursor: pointer; }
.mahjong-tile.free:hover { filter: brightness(1.08) drop-shadow(0 0 7px rgba(242,200,91,.7)) drop-shadow(0 6px 3px rgba(0,0,0,.3)); }
.mahjong-tile.selected { z-index: 1900 !important; transform: translate(calc(var(--lift-x) * 1px), calc((var(--lift-y) - 6) * 1px)) scale(1.07); filter: drop-shadow(0 0 7px #65ffd0) drop-shadow(0 8px 3px rgba(0,0,0,.35)); }
.mahjong-tile.selected .tile-face { outline: 3px solid var(--mint); outline-offset: 1px; }
.mahjong-tile.hint .tile-face { animation: hintGlow .45s ease-in-out 4 alternate; }
.mahjong-tile.bad { animation: badTile .22s ease 2; }
.mahjong-tile.removing { pointer-events: none; animation: tileRemove .42s cubic-bezier(.2,.9,.2,1) forwards; }
@keyframes hintGlow { to { outline: 4px solid var(--gold); filter: brightness(1.2); } }
@keyframes badTile { 25% { transform: translate(calc((var(--lift-x) - 4) * 1px), calc(var(--lift-y) * 1px)); } 75% { transform: translate(calc((var(--lift-x) + 4) * 1px), calc(var(--lift-y) * 1px)); } }
@keyframes tileRemove { 30% { transform: translate(calc(var(--lift-x) * 1px), calc((var(--lift-y) - 12) * 1px)) scale(1.15); filter: drop-shadow(0 0 16px #fff6a3); } 100% { opacity: 0; transform: translate(calc(var(--lift-x) * 1px), calc((var(--lift-y) - 38) * 1px)) scale(.3) rotate(9deg); } }

.effect-layer { position: absolute; inset: 0; pointer-events: none; z-index: 1950; }
.score-pop { position: absolute; left: var(--px); top: var(--py); color: #fff4a1; font: 1000 24px/1 "Arial Black", "Yu Gothic UI", sans-serif; text-shadow: 0 2px 0 #8f2530, 0 0 10px #ff3c4c; animation: scorePop .8s ease-out forwards; }
@keyframes scorePop { 0% { opacity: 0; transform: translate(-50%, 8px) scale(.6); } 18% { opacity: 1; transform: translate(-50%, 0) scale(1.2); } 100% { opacity: 0; transform: translate(-50%, -46px) scale(.95); } }
.fever-banner { position: absolute; z-index: 1990; left: 50%; top: 47%; transform: translate(-50%,-50%) scale(.7); width: 220px; padding: 12px; text-align: center; color: #fff8d0; background: rgba(160,21,30,.92); border: 3px solid var(--gold); box-shadow: 0 0 0 5px rgba(255,255,255,.8), 0 12px 40px rgba(0,0,0,.45); opacity: 0; pointer-events: none; }
.fever-banner small { display: block; font: 900 11px Consolas, monospace; }
.fever-banner strong { font-family: "Yu Mincho", serif; font-size: 42px; }
.fever-banner.show { animation: feverShow .9s ease both; }
@keyframes feverShow { 0% { opacity: 0; transform: translate(-50%,-50%) scale(.45) rotate(-7deg); } 20%,75% { opacity: 1; transform: translate(-50%,-50%) scale(1); } 100% { opacity: 0; transform: translate(-50%,-50%) scale(1.15); } }
.game-shell.fever { animation: feverFrame .5s ease; }
@keyframes feverFrame { 50% { box-shadow: inset 0 0 55px rgba(255,215,70,.62); } }

.controls { position: relative; z-index: 2100; display: grid; grid-template-columns: 1fr .86fr 1fr; gap: 7px; padding: 8px 9px max(9px, env(safe-area-inset-bottom)); background: rgba(3,27,24,.96); border-top: 1px solid var(--line); }
.tool-button { min-width: 0; min-height: 49px; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 5px 7px; color: var(--ivory); background: #0b4a40; border: 1px solid #2f806e; border-radius: 5px; }
.tool-button:disabled { opacity: .38; cursor: not-allowed; }
.tool-icon { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; color: #102018; background: var(--gold); border-radius: 50%; font-size: 18px; font-weight: 1000; }
.tool-button span:last-child { min-width: 0; text-align: left; }
.tool-button b { display: block; font-size: 12px; white-space: nowrap; }
.tool-button small { display: block; color: #b9d9cf; font-size: 9px; white-space: nowrap; }
.tool-button i { color: #fff; font-style: normal; }
.pace-display { display: flex; flex-direction: column; align-items: center; justify-content: center; border-inline: 1px solid rgba(255,255,255,.12); }
.pace-display span { color: #9fc8bd; font: 800 8px Consolas, monospace; }
.pace-display strong { color: var(--gold); font: 900 22px Consolas, monospace; }

.modal-screen { position: fixed; z-index: 5000; inset: 0; display: none; place-items: center; padding: 20px; background: rgba(1,15,13,.82); backdrop-filter: blur(8px); }
.modal-screen.open { display: grid; }
.modal-card { position: relative; width: min(100%, 400px); padding: 28px 22px; text-align: center; color: var(--ink); background: #fff9e8; border: 3px solid var(--gold); box-shadow: 0 0 0 6px #084339, 0 20px 70px rgba(0,0,0,.55); }
.modal-card > p { margin: 0; color: #a31f28; font: 900 11px Consolas, monospace; }
.modal-card h2 { margin: 6px 0 22px; font-family: "Yu Mincho", serif; font-size: 30px; }
.primary-button, .secondary-button { width: 100%; min-height: 50px; border-radius: 4px; font-size: 16px; font-weight: 900; }
.primary-button { color: #fff; background: #0b6554; border: 2px solid #08483d; }
.secondary-button { margin-top: 9px; color: #263b35; background: #eee5cd; border: 1px solid #c7b98f; }
.modal-close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; color: #fff; background: #9d2730; font-size: 25px; }
.ranking-list { margin: 0; padding: 0; list-style: none; text-align: left; }
.ranking-list li { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; min-height: 45px; padding: 7px 4px; border-bottom: 1px solid #d7caa5; }
.ranking-list li span { display: grid; place-items: center; width: 28px; height: 28px; color: #fff; background: #0b6554; }
.ranking-list li strong { font: 900 20px Consolas, monospace; }
.ranking-list li small { color: #52645e; }
.ranking-list .empty-record { display: block; padding: 22px 0; color: #64736f; text-align: center; }

.result-screen { text-align: center; }
.result-screen.active { display: grid; place-items: center; }
.result-content { width: 100%; padding: 28px 20px max(28px, env(safe-area-inset-bottom)); }
.result-kicker { color: var(--gold); }
.result-content h2 { margin: 4px 0 16px; font-family: "Yu Mincho", serif; font-size: clamp(34px, 10vw, 48px); }
.result-score { width: min(100%, 390px); margin: 0 auto 16px; padding: 15px; color: var(--ink); background: var(--ivory); border: 3px solid var(--gold); box-shadow: 0 7px 0 #88722f; }
.result-score span { display: block; color: #8f2730; font: 900 11px Consolas, monospace; }
.result-score strong { display: block; font: 1000 clamp(38px, 12vw, 56px) Consolas, monospace; }
.result-score em { display: none; width: max-content; margin: 4px auto 0; padding: 3px 8px; color: #fff; background: var(--red); font: normal 900 11px Consolas, monospace; }
.result-score em.show { display: block; }
.result-grid { width: min(100%, 390px); margin: 0 auto 19px; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.result-grid div { min-height: 65px; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-grid div:nth-child(even) { border-right: 0; }
.result-grid div:nth-child(n+3) { border-bottom: 0; }
.result-grid span { color: #a7ccc0; font-size: 11px; }
.result-grid strong { margin-top: 3px; font: 900 19px Consolas, monospace; }

@media (min-width: 720px) {
  body { padding-block: 14px; }
  .game-shell { min-height: calc(100dvh - 28px); border: 1px solid rgba(242,200,91,.28); box-shadow: 0 18px 80px rgba(0,0,0,.45); }
  .screen { min-height: calc(100dvh - 80px); }
  .play-screen.active { min-height: calc(100dvh - 80px); }
}

@media (max-width: 380px) {
  .topbar { grid-template-columns: 40px 1fr auto; padding-inline: 7px; }
  .icon-button { width: 35px; height: 35px; }
  .brand { font-size: 15px; }
  .title-content { padding-inline: 16px; }
  .title-copy { font-size: 13px; }
  .hud-item { padding-inline: 7px; }
  .status-line { padding-inline: 6px; }
  .tool-button { gap: 4px; padding-inline: 4px; }
  .tool-icon { width: 24px; height: 24px; flex-basis: 24px; font-size: 15px; }
}

@media (max-height: 720px) {
  .title-content { padding-top: 14px; }
  .title-copy { margin-block: 8px 2px; line-height: 1.5; }
  .title-tower { height: 210px; }
  .title-record { margin-top: -8px; }
  .hud { min-height: 51px; }
  .controls { padding-top: 5px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .tool-button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
