:root {
  color-scheme: light;
  --cream: #fff9ef;
  --paper: #fbf5e9;
  --cocoa: #604535;
  --muted: #967b63;
  --edge: #dbc4a7;
  --caramel: #b96b3e;
  --board-width: min(350px, calc((100svh - 195px) / 2));
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  font-weight: 600;
  color: var(--cocoa);
  background: #f5ecdc;
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; padding: 16px 20px 14px;
  display: flex; flex-direction: column; align-items: center;
  background:
    radial-gradient(ellipse at 8% 10%, #fffaf1 0, transparent 47%),
    radial-gradient(ellipse at 96% 84%, #ecd8bc99 0, transparent 48%),
    repeating-linear-gradient(0deg, #d4bc9912 0px, #d4bc9912 1px, transparent 1px, transparent 5px),
    #f5ecdc;
}
h1,h2,p { margin: 0; }
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
canvas,svg,img { display: block; }
canvas { user-select: none; }
button:focus-visible { outline: 3px solid #a45c32; outline-offset: 4px; }
.hidden { display: none !important; }
.wood-card {
  background: linear-gradient(135deg, #fffdf5ee, #faf1e3f5);
  border: 1px solid var(--edge); border-radius: 18px;
  box-shadow: 0 5px 0 #c4a88420, 0 12px 26px #6f492210, inset 0 1px 0 #fff;
}
.title-band {
  width: min(960px, 100%); min-height: 94px;
  padding: 10px 23px; margin-bottom: 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border-bottom: 3px solid #c5a07b;
}
.brand { display: flex; align-items: center; gap: 20px; }
.title-logo { width: 164px; height: auto; }
.brand p { font-size: 12px; letter-spacing: .08em; color: #8b6b52; }
.header-actions { display: flex; align-items: center; gap: 9px; }
.button {
  border: 1px solid #c9aa85; border-radius: 12px;
  min-height: 44px; padding: 9px 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  color: var(--cocoa); box-shadow: 0 3px 0 #c9ac8980, inset 0 1px 0 #ffffffaa;
  transition: transform .1s, background-color .15s, box-shadow .1s;
}
.button:active, .button.is-pressed { transform: translateY(3px); box-shadow: 0 0 0 #c9ac8900, inset 0 2px 3px #69412230; }
.button-quiet { background: #fffaf0; }
.button-primary { background: linear-gradient(#a8613b, #92502f); border-color: #87492b; color: #fffaf2; text-shadow: 0 1px 0 #7a492538; box-shadow: 0 3px 0 #8e552c80, inset 0 1px 0 #f5d1ad; }
.button-pad { background: linear-gradient(#fffdf4, #f3e5cd); }
.button-pad.button-primary { background: linear-gradient(#a8613b, #92502f); }
#ctrlHard { border-color: #94512e; box-shadow: 0 4px 0 #8e552cb3, inset 0 1px 0 #f5d1ad; }
#ctrlHard:active, #ctrlHard.is-pressed { box-shadow: inset 0 2px 4px #6e391c66; }
@media (hover: hover) and (pointer: fine) {
  .button:hover { transform: translateY(-1px); box-shadow: 0 4px 0 #c9ac8980, inset 0 1px 0 #fff; }
  .button-primary:hover { box-shadow: 0 4px 0 #8e552c99, inset 0 1px 0 #f5d1ad; }
  .button:active, .button.is-pressed { transform: translateY(3px); box-shadow: inset 0 2px 3px #69412230; }
}
#soundIcon { font-size: 17px; }
#soundText { font-size: 11px; }
.game-layout {
  display: grid; grid-template-columns: 180px auto 180px;
  gap: 24px; align-items: start; width: fit-content; max-width: 100%;
}
.side-panel { display: flex; flex-direction: column; gap: 20px; padding-top: 29px; }
h2 { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 10px; }
h2 > span { letter-spacing: .18em; font-size: 11px; }
h2 > small { font-size: 11px; font-weight: 600; color: #92735b; }
.preview-card { display: flex; align-items: center; flex-direction: column; padding: 17px 12px 12px; }
.preview-card canvas { background: #eee1cc80; border-radius: 12px; margin: 12px 0 7px; }
#holdCanvas { width: 114px; height: 114px; }
#nextCanvas { width: 112px; height: 246.4px; }
.key-hint { font-size: 10px; color: #92735b; line-height: 1.5; }
.hold-used #holdCanvas { opacity: .65; }
.mascot-card { padding: 17px 12px 14px; text-align: center; }
.mascot-card h2 > span { font-size: 9px; }
.floating-mascot { background: none; border: none; padding: 0; margin: 8px auto; width: 134px; height: 134px; }
.floating-mascot img { width: 100%; height: 100%; object-fit: contain; }
.speech-bubble { position: relative; margin-top: 11px; padding: 11px 7px; border-radius: 12px; border: 1px solid #d9bd96; background: #fff6e3; font-size: 11px; line-height: 1.7; min-height: 54px; transition: transform .2s; }
.speech-bubble::before { content: ''; position: absolute; top: -6px; left: calc(50% - 5px); width: 10px; height: 10px; transform: rotate(45deg); background: #fff6e3; border-left: 1px solid #d9bd96; border-top: 1px solid #d9bd96; }
.scale-105 { transform: scale(1.025); }
.play-column { display: flex; align-items: center; flex-direction: column; }
.board-label { display: flex; align-items: center; gap: 18px; height: 29px; font-size: 10px; color: #9a7a5e; letter-spacing: .13em; }
.board-label > span { font-size: 11px; opacity: .6; }
.board-frame {
  position: relative; padding: 10px; border-radius: 20px;
  border: 1px solid #ae835d;
  background: repeating-linear-gradient(3deg, #8f654210 0, #8f654210 1px, transparent 2px, transparent 7px), linear-gradient(100deg, #b58e65, #d2af80 45%, #b88b5f);
  box-shadow: inset 0 2px 1px #f9dfb9, inset 0 -3px 2px #79523166, 0 8px 0 #b89a7640, 0 20px 40px #63432920;
}
#tetrisCanvas { width: var(--board-width); height: auto; aspect-ratio: 1/2; border-radius: 10px; box-shadow: 0 0 0 2px #876143; }
.game-overlay { position: absolute; inset: 10px; background: #4d382ee8; backdrop-filter: blur(5px); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 18px 12px; gap: 13px; color: #fff2da; }
.game-overlay h2 { display: block; font-size: clamp(17px, 2vw, 24px); }
.game-overlay > p { font-size: 10px; line-height: 1.8; color: #e4cbb0; }
.overlay-symbol { font-size: 33px; color: #efc797; }
.final-stats { padding: 12px 18px; width: 90%; border: 1px solid #b49673; border-radius: 12px; background: #fff2dc; color: var(--cocoa); font-size: 11px; display: flex; flex-direction: column; gap: 8px; }
.final-stats > div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.final-stats strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.stats-card { padding: 17px 15px 11px; }
.stats-card h2 { margin-bottom: 14px; }
.stats-card h2 > span { font-size: 9px; }
.stat { display: flex; align-items: baseline; justify-content: space-between; padding: 10px 0; gap: 8px; font-size: 11px; border-bottom: 1px solid #dfcbb2; }
.stat:last-child { border: 0; }
.stat strong { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.score-stat strong { color: #a45f34; font-size: 27px; }
#touchControls { display: none; width: 100%; padding-bottom: env(safe-area-inset-bottom); }
.touch-grid { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 7px; padding: 9px 0 3px; }
.touch-grid .button { padding: 4px 0; min-width: 44px; min-height: 49px; flex-direction: column; gap: 0; }
.touch-grid .button > span { font-size: 24px; line-height: 26px; }
.touch-grid .button > small { font-size: 10px; line-height: 17px; }
.touch-grid .soft-drop { grid-column: 1/-1; flex-direction: row; min-height: 42px; font-size: 22px; }
footer { width: min(960px,100%); margin: 24px auto 0; text-align: center; color: #92745d; font-size: 10px; line-height: 1.9; }
footer > span { font-size: 9px; letter-spacing: .13em; opacity: .8; }
footer i { padding: 0 7px; font-style: normal; opacity: .5; }
kbd { display: inline-block; font: inherit; padding: 0 3px; min-width: 17px; border: 1px solid #d9c4a6; border-radius: 4px; background: #fffaf080; }
@media (max-width: 880px) and (min-width: 768px) { .brand p { display: none; } .game-layout { grid-template-columns: 150px auto 150px; gap: 16px; } }
@media (min-width: 768px) and (pointer: coarse) { #touchControls { display: block; } }
@media (max-width: 767px) {
  :root { --board-width: min(300px, calc((100svh - 330px) / 2)); }
  body { padding: 8px 12px 12px; }
  .title-band { min-height: 66px; padding: 5px 10px; margin-bottom: 10px; border-radius: 15px; gap: 8px; }
  .title-logo { width: 110px; }
  .brand p { display: none; }
  .header-actions { gap: 5px; }
  .header-actions .button { min-height: 44px; padding: 7px 8px; font-size: 10px; border-radius: 10px; }
  #soundToggleBtn { width: 44px; min-width: 44px; padding: 0; }
  #soundText { display: none; }
  .game-layout { width: 100%; grid-template-columns: 84px minmax(0,1fr); grid-template-areas: 'hold next' 'play play' 'stats stats' 'mascot mascot'; gap: 12px; }
  .side-panel { display: contents; }
  #holdCard { grid-area: hold; }
  #nextCard { grid-area: next; }
  #statsCard { grid-area: stats; }
  #mascotCard { grid-area: mascot; }
  .play-column { grid-area: play; }
  .preview-card { padding: 7px 4px 3px; border-radius: 12px; min-height: 74px; }
  .preview-card h2 { flex-direction: row; gap: 6px; }
  .preview-card h2 > span { font-size: 9px; letter-spacing: .1em; }
  .preview-card h2 > small { font-size: 9px; }
  .preview-card .key-hint { display: none; }
  .preview-card canvas { margin: 2px 0 0; border-radius: 8px; background: transparent; }
  #holdCanvas { width: 55px; height: 55px; }
  #nextCanvas { width: min(240px,100%); height: auto; aspect-ratio: 4/1; }
  .board-label { display: none; }
  .board-frame { padding: 7px; border-radius: 15px; }
  #tetrisCanvas { border-radius: 8px; }
  #touchControls { display: block; width: 100%; }
  .touch-grid { padding-top: 11px; gap: 8px; }
  .touch-grid .button { min-height: 48px; border-radius: 11px; }
  .touch-grid .soft-drop { min-height: 44px; }
  .game-overlay { inset: 7px; padding: 10px 6px; gap: 9px; }
  .game-overlay > p { font-size: 9px; }
  .game-overlay .button { padding: 8px 10px; font-size: 10px; min-height: 44px; }
  .overlay-symbol { font-size: 24px; }
  .final-stats { padding: 8px; width: 95%; font-size: 9px; }
  .final-stats strong { font-size: 14px; }
  .stats-card { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); padding: 12px 15px; gap: 16px; border-radius: 13px; }
  .stats-card h2 { display: none; }
  .stat { display: flex; flex-direction: column; gap: 3px; padding: 0; border: 0; font-size: 10px; }
  .stat strong, .score-stat strong { font-size: 21px; }
  .mascot-card { display: grid; grid-template-columns: 75px 1fr; align-items: center; gap: 9px; padding: 9px 13px; border-radius: 14px; }
  .mascot-card h2 { display: none; }
  .floating-mascot { width: 75px; height: 75px; margin: 0; }
  .speech-bubble { margin: 0; min-height: 44px; display: flex; align-items: center; justify-content: center; }
  .speech-bubble::before { top: calc(50% - 5px); left: -6px; transform: rotate(-45deg); }
  footer { margin-top: 12px; font-size: 9px; }
  footer i { padding: 0 3px; }
}
@media (max-width: 350px) { .title-logo { width: 84px; } .title-band { padding: 5px 7px; } .header-actions .button { padding: 7px 6px; } }
@media (max-height: 600px) and (max-width: 767px) { .game-overlay h2 { font-size: 15px; } .game-overlay { gap: 7px; } .overlay-symbol { font-size: 20px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }

.preview-heading { display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 10px; }
.preview-heading > span { letter-spacing: .18em; font-size: 11px; }
.preview-heading > small { font-size: 11px; font-weight: 600; color: #92735b; }
/* Direct gestures are scoped to the board; the rest of the page can still scroll. */
#tetrisCanvas { touch-action: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.hold-card { width: 100%; color: inherit; }
.hold-card:focus-visible { outline: 3px solid #a45c32; outline-offset: 3px; }
.hold-card:not(:disabled):active { box-shadow: inset 0 2px 5px #69412230; }
.hold-card:disabled { cursor: default; }
.touch-guide, .button-controls { display: none; }
.touch-guide { margin-top: 10px; color: #795b43; text-align: center; font-size: 10px; line-height: 1.8; }
.button-controls { width: 100%; margin-top: 6px; }
.button-controls > summary { min-height: 44px; padding: 12px 8px; text-align: center; font-size: 11px; cursor: pointer; touch-action: manipulation; }
.button-controls > summary:focus-visible { outline: 3px solid #a45c32; border-radius: 8px; }
.button-controls #touchControls { display: block; }
.button-controls .soft-drop { min-height: 44px; }
@media (pointer: coarse), (max-width: 767px) {
  .touch-guide, .button-controls { display: block; }
}
@media (max-width: 767px) {
  :root { --board-width: min(340px, calc(100vw - 42px), max(140px, calc((100svh - 250px) / 2))); }
  .preview-card .preview-heading { flex-direction: row; gap: 6px; }
  .preview-heading > span { font-size: 9px; letter-spacing: .1em; }
  .preview-heading > small { font-size: 9px; }
  .game-layout { gap: 10px; }
  .title-band { position: sticky; top: 8px; z-index: 5; }
  footer > p { display: none; }
}
@media (min-width: 768px) and (pointer: coarse) {
  :root { --board-width: min(350px, calc((100svh - 240px) / 2), calc(100vw - 400px)); }
  .game-layout { gap: 16px; grid-template-columns: 150px auto 150px; }
}

/* Phase 4: the slow switch shares the existing menu's visual language. */
#slowBtn { min-width: 112px; }
#slowBtn.is-slow { color: #314d31; background: #e0ebcd; border-color: #84966b; box-shadow: 0 3px 0 #84966b60, inset 0 1px 0 #fff; }
@media (max-width: 767px) {
  .header-actions { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 5px; }
  .header-actions .button { min-height: 44px; }
  #soundToggleBtn { width: auto; }
  #slowBtn { min-width: 0; font-size: 10px; }
  .title-band { min-height: 104px; }
}
