/* ============================================================
   TETRIS.NOW — game board, shell, and content components.
   The board itself is drawn on <canvas> by tetris.js; this file styles the
   arcade frame around it plus every below-the-fold content component.
   Generic board class names are scoped under .tetris-layout so they never
   leak onto content pages.
   ============================================================ */

/* ---- Full-width intro block (first two paragraphs, no reading-column cap) ---- */
.page-intro { padding-top: .25rem; }
.page-intro p { max-width: none; font-size: 1.05rem; color: var(--text-muted); margin-bottom: 1rem; }
.page-intro p strong { color: var(--text); }
.home-intro { max-width: none; font-size: 1.05rem; margin: .25rem 0 1.25rem; color: var(--text-muted); }

/* ---- Game header + mode tabs ---- */
.game-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.game-header h1 { font-size: 1.9rem; line-height: 1.1; }
.game-header .tagline { display: block; color: var(--text-muted); font-size: 1rem; margin-top: .35rem; max-width: 60ch; }
.mode-tabs { display: inline-flex; background: var(--surface-3); border-radius: 999px; padding: .25rem; gap: .15rem; flex-wrap: wrap; }
.mode-tab { padding: .4rem .95rem; border-radius: 999px; font-weight: 600; font-size: .9rem; color: var(--text-muted); white-space: nowrap; }
.mode-tab:hover { color: var(--blue); }
.mode-tab.active { background: var(--blue); color: #fff; box-shadow: var(--shadow-sm); }

/* ---- The game shell: an arcade cabinet card ---- */
.game-shell {
  background: linear-gradient(180deg, #141a2e 0%, #0d1226 100%);
  border: 1px solid #2a3352;
  border-radius: var(--radius-lg);
  padding: .9rem;
  box-shadow: var(--shadow-lg), inset 0 0 0 1px rgba(255,255,255,.02);
  color: #e7ecff;
}
.game-shell:fullscreen { display: flex; flex-direction: column; justify-content: center; padding: 1.2rem; }

/* Toolbar */
.game-toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .8rem; }
.game-stats { display: flex; gap: 1.1rem; flex-wrap: wrap; }
.game-stats > span { display: flex; flex-direction: column; line-height: 1.15; font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.15rem; color: #fff; }
.game-stats .stat-label { font-size: .62rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: #8ea0d0; }
.game-buttons { display: flex; gap: .4rem; flex-wrap: wrap; }
.btn-felt {
  background: #202844; color: #d8e0ff; border: 1px solid #33406b;
  border-radius: var(--radius-sm); padding: .5rem .8rem; font-size: .85rem; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: background .12s, transform .05s, box-shadow .12s;
}
.btn-felt:hover { background: #2a3660; border-color: #4b5c96; }
.btn-felt:active { transform: translateY(1px); }
.btn-felt-primary { background: linear-gradient(180deg, #8b5cf6, #6d28d9); border-color: #7c3aed; color: #fff; box-shadow: 0 0 14px rgba(124,58,237,.4); }
.btn-felt-primary:hover { background: linear-gradient(180deg, #9d70f8, #7c3aed); }

/* ---- Board layout (built by tetris.js inside #board-wrap) ----
   Reserve the board's final height up front so injecting the canvas + side
   panels does not push the page down (CLS). The well is a fixed 10x20 at
   cell=30 (300x600px) across the common viewport range, so the reserved
   heights are deterministic: ~600px side-by-side, ~1121px once the panels
   stack below the well at <=520px (see the responsive block further down).
   min-height only sets a floor, so any narrower board just leaves a little
   slack instead of a reverse shift. */
#board-wrap { display: flex; justify-content: center; align-items: flex-start; min-height: var(--board-reserve, 600px); }
.tetris-layout { display: flex; gap: .8rem; align-items: flex-start; justify-content: center; width: 100%; }
.tetris-side { display: flex; flex-direction: column; gap: .7rem; flex: 0 0 auto; }
.tetris-side-left { align-items: flex-end; }
.tetris-box { background: rgba(10,15,32,.7); border: 1px solid #2a3352; border-radius: var(--radius-sm); padding: .4rem .5rem .5rem; text-align: center; }
.tbx-label { font-size: .62rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: #8ea0d0; margin-bottom: .3rem; }
.tetris-box canvas { display: block; }
.tetris-mini { display: flex; flex-direction: column; gap: .5rem; margin-top: .2rem; }
.tetris-mini .tm-row { background: rgba(10,15,32,.6); border: 1px solid #232c48; border-radius: var(--radius-sm); padding: .35rem .5rem; min-width: 74px; }
.tetris-mini .tm-lbl { font-size: .58rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #8ea0d0; }
.tetris-mini .tm-val { font-size: 1.05rem; font-weight: 800; color: #fff; font-variant-numeric: tabular-nums; }

.tetris-well-wrap { position: relative; flex: 0 0 auto; }
.tetris-well {
  display: block; border-radius: 6px;
  background: radial-gradient(120% 120% at 50% 0%, var(--well-bg-2), var(--well-bg));
  box-shadow: 0 0 0 2px #2a3352, 0 0 34px rgba(124,58,237,.18), inset 0 0 40px rgba(0,0,0,.55);
  touch-action: none;
}
.tetris-msg {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  flex-direction: column; text-align: center; background: rgba(6,10,22,.72); border-radius: 6px;
  color: #fff; font-weight: 800; font-size: 1.4rem; letter-spacing: .02em; backdrop-filter: blur(2px);
  padding: 1rem;
}
.tetris-msg.show { display: flex; }
.tetris-msg small { display: block; font-weight: 600; font-size: .85rem; color: #b9c4ec; margin-top: .5rem; }
/* floating combo/line popups */
.tetris-flash { position: absolute; left: 50%; top: 42%; transform: translate(-50%,-50%); pointer-events: none;
  font-weight: 900; font-size: 1.5rem; color: #fff; text-shadow: 0 0 12px rgba(124,58,237,.9); opacity: 0;
  animation: tflash 700ms ease-out forwards; letter-spacing: .03em; }
@keyframes tflash { 0% { opacity: 0; transform: translate(-50%,-38%) scale(.7);} 20%{opacity:1;} 100% { opacity: 0; transform: translate(-50%,-70%) scale(1.1);} }

/* ---- Mobile touch controls ---- */
.tetris-touch { display: none; gap: .5rem; margin-top: .7rem; justify-content: center; flex-wrap: wrap; }
.tetris-touch button {
  flex: 1 1 0; min-width: 56px; max-width: 84px; height: 52px; font-size: 1.3rem;
  background: #202844; color: #e7ecff; border: 1px solid #33406b; border-radius: var(--radius-sm);
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
.tetris-touch button:active { background: #2f3c6a; }
body.touch-device .tetris-touch { display: flex; }
/* Belt-and-suspenders: show the pad on any touch/coarse-pointer device even if
   the JS capability check never ran. */
@media (pointer: coarse) { .tetris-touch { display: flex; } }

/* Mobile gesture hint (shown only on touch devices, replaces keyboard hint) */
.touch-hint { display: none; }
body.touch-device .touch-hint { display: block; }
body.touch-device .kbd-hint { display: none; }

/* ---- Win / game-over overlay ---- */
.game-overlay { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; z-index: 40; }
.game-shell { position: relative; }
.game-overlay.show { display: flex; }
.game-overlay-card {
  background: linear-gradient(180deg, #1b2140, #10152b); border: 1px solid #34406b; color: #fff;
  border-radius: var(--radius-lg); padding: 1.6rem 1.8rem; text-align: center; max-width: 420px; width: 92%;
  box-shadow: 0 20px 60px rgba(0,0,0,.5), 0 0 30px rgba(124,58,237,.25);
}
.overlay-title { font-size: 1.7rem; font-weight: 900; margin-bottom: .35rem; }
.game-overlay-card p { color: #c4cdf0; margin-bottom: 1rem; }
.win-stats { display: flex; justify-content: center; gap: 1.4rem; margin: 1rem 0; }
.win-stats .num { font-size: 1.5rem; font-weight: 900; color: #fff; font-variant-numeric: tabular-nums; }
.win-stats .lbl { font-size: .62rem; text-transform: uppercase; letter-spacing: .08em; color: #8ea0d0; font-weight: 700; }
.overlay-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; margin-top: .4rem; }
#win-rank { color: #a78bfa; font-weight: 700; }

/* ---- Stats strip (per-game browser stats) ---- */
/* min-height reserves the one-row strip so it does not nudge content when
   tetris.js fills it on init (it always renders >=3 stat tiles). */
.stats-strip { display: flex; flex-wrap: wrap; gap: .6rem; margin: 1rem 0 0; justify-content: center; min-height: 64px; }
.stats-strip .ss-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: .5rem .85rem; text-align: center; min-width: 84px; }
.stats-strip .ss-val { font-size: 1.2rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.stats-strip .ss-lbl { font-size: .62rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-light); font-weight: 700; }

/* ============================================================
   Below-the-fold content components
   ============================================================ */
.game-content { padding: 2rem 0 0; }
.game-content h2 { font-size: 1.6rem; margin: 2rem 0 .8rem; }
.game-content h3 { font-size: 1.2rem; margin: 1.4rem 0 .6rem; }
.game-content p { margin-bottom: 1rem; }
.game-content > p, .game-content ul, .game-content ol, .game-content table { max-width: none; }
.game-content a:not(.btn) { color: var(--blue); font-weight: 600; }
.game-content a:not(.btn):hover { text-decoration: underline; }
/* Buttons rendered as links keep their own button colors (white on purple, etc.). */
.game-content a.btn-primary, .game-content a.btn-accent, .game-content a.btn-danger { color: #fff; }
.game-content a.btn-primary:hover, .game-content a.btn-accent:hover, .game-content a.btn-danger:hover { color: #fff; }

.tldr { background: var(--blue-light); border: 1px solid var(--blue-border); border-left: 4px solid var(--blue); border-radius: var(--radius-sm); padding: .9rem 1.1rem; color: var(--text); }
.tldr strong { color: var(--blue-dark); }
.tip-callout { background: var(--accent-light); border: 1px solid #a5f3fc; border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: .8rem 1.1rem; }

.facts-table { width: 100%; border-collapse: collapse; margin: .5rem 0 1rem; }
.facts-table th, .facts-table td { text-align: left; padding: .6rem .8rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.facts-table th { width: 34%; color: var(--text); font-weight: 700; background: var(--surface-2); }
.facts-table td { color: var(--text-muted); }

/* How-to cards */
.howto-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; margin: 1rem 0; }
.howto-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.howto-card h3 { margin: .8rem 1rem .3rem; font-size: 1.05rem; }
.howto-card p { margin: 0 1rem 1rem; color: var(--text-muted); font-size: .95rem; }
.howto-card.has-img .howto-img { width: 100%; height: 168px; object-fit: cover; background: var(--well-bg); display: block; }

/* Strategy lists */
.strategy-list { margin: .6rem 0 1rem; padding-left: 1.3rem; }
.strategy-list li { margin-bottom: .6rem; color: var(--text-muted); }
.strategy-list.numbered { list-style: none; counter-reset: strat; padding-left: 0; }
.strategy-list.numbered li { counter-increment: strat; position: relative; padding-left: 2.4rem; min-height: 1.8rem; margin-bottom: .8rem; }
.strategy-list.numbered li::before { content: counter(strat); position: absolute; left: 0; top: -.1rem; width: 1.7rem; height: 1.7rem; background: var(--blue); color: #fff; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: .85rem; }

/* FAQ accordion */
.faq-accordion { margin: 1rem 0; display: flex; flex-direction: column; gap: .5rem; }
.faq-acc-item { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.faq-acc-item summary { list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .9rem 1.1rem; }
.faq-acc-item summary::-webkit-details-marker { display: none; }
.faq-acc-item summary h3 { font-size: 1.02rem; margin: 0; color: var(--text); }
.faq-acc-chevron { color: var(--text-light); flex-shrink: 0; transition: transform .18s; }
.faq-acc-item[open] .faq-acc-chevron { transform: rotate(180deg); }
.faq-acc-body { padding: 0 1.1rem 1rem; }
.faq-acc-body p { margin: 0; color: var(--text-muted); }

/* Variant cards */
.variant-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; margin: 1rem 0; }
.variant-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow-sm); transition: transform .12s, box-shadow .12s, border-color .12s; display: block; }
.variant-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--blue-border); }
.vc-name { font-weight: 800; color: var(--text); margin-bottom: .3rem; }
.vc-tag { color: var(--text-muted); font-size: .9rem; margin-bottom: .5rem; }
.vc-meta { color: var(--text-light); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* Rating widget */
.rating-widget { display: inline-flex; align-items: center; gap: .5rem; margin: 1rem 0 0; padding: .6rem .9rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; }
.rating-widget .rating-label { font-size: .85rem; color: var(--text-muted); font-weight: 600; }
.rating-stars { display: inline-flex; }
.rating-star { font-size: 1.35rem; color: #cbd5e1; cursor: pointer; line-height: 1; transition: color .1s; background: none; border: none; padding: 0 1px; }
.rating-star.on { color: var(--accent); }
.rating-summary { font-size: .8rem; color: var(--text-light); font-weight: 600; }

/* ---- Multiplayer ---- */
.mp-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow-sm); }
.mp-players { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin: 1rem 0; }
.mp-player { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.mp-player.is-you { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue-light); }
.mp-player .mp-name { font-weight: 800; color: var(--text); }
.mp-player .mp-slot { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-light); font-weight: 700; }
.mp-progress { height: 12px; background: var(--surface-3); border-radius: 999px; overflow: hidden; margin: .6rem 0; }
.mp-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--accent)); transition: width .25s; }
.mp-presence { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; margin-right: .35rem; }
.mp-presence.on { background: #22c55e; }
.mp-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.6rem; font-weight: 800; letter-spacing: .25em; color: var(--blue); background: var(--blue-light); border: 1px dashed var(--blue-border); border-radius: var(--radius-sm); padding: .5rem 1rem; display: inline-block; }
.mp-chat { border: 1px solid var(--border); border-radius: var(--radius-sm); height: 180px; overflow-y: auto; padding: .6rem; background: var(--surface-2); font-size: .9rem; }
.mp-chat .mpc-line { margin-bottom: .3rem; }
.mp-chat .mpc-name { font-weight: 700; color: var(--blue); }

/* ---- Settings modal (window.TNSettings) ---- */
.tn-modal-overlay { position: fixed; inset: 0; background: rgba(8,12,24,.6); display: none; align-items: center; justify-content: center; z-index: 4000; padding: 1rem; }
.tn-modal-overlay.show { display: flex; }
.tn-modal { background: var(--surface); border-radius: var(--radius-lg); max-width: 460px; width: 100%; box-shadow: var(--shadow-lg); overflow: hidden; }
.tn-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.tn-modal-head h3 { margin: 0; }
.tn-modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-light); line-height: 1; }
.tn-modal-body { padding: 1.2rem; display: flex; flex-direction: column; gap: 1.1rem; }
.tn-set-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.tn-set-row .tn-set-label { font-weight: 700; color: var(--text); }
.tn-set-row .tn-set-desc { font-size: .8rem; color: var(--text-light); }
.tn-swatches { display: flex; gap: .45rem; flex-wrap: wrap; }
.tn-swatch { width: 30px; height: 30px; border-radius: 7px; cursor: pointer; border: 2px solid transparent; box-shadow: var(--shadow-sm); }
.tn-swatch.sel { border-color: var(--text); }
.tn-toggle { position: relative; width: 46px; height: 26px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); cursor: pointer; flex-shrink: 0; }
.tn-toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: left .15s; }
.tn-toggle.on { background: var(--blue); border-color: var(--blue); }
.tn-toggle.on::after { left: 22px; }

/* ---- 404 hero (nf-*) ---- */
.nf-hero { text-align: center; padding: 3rem 0; }
.nf-blocks { display: flex; gap: .3rem; justify-content: center; margin-bottom: 1.5rem; }
.nf-blocks span { width: 34px; height: 34px; border-radius: 5px; box-shadow: inset 0 -4px 0 rgba(0,0,0,.25); }
.btn-outline-light { border: 1px solid rgba(255,255,255,.6); color: #fff; }

/* ---- Responsive ---- */
@media (max-width: 680px) {
  .tetris-layout { gap: .45rem; }
  .tetris-side-left { order: 2; }
  .game-header h1 { font-size: 1.5rem; }
  .game-stats > span { font-size: 1rem; }
  .win-stats { gap: 1rem; }
}
@media (max-width: 520px) {
  .tetris-side { flex-direction: row; }
  .tetris-side-left { order: 2; width: 100%; justify-content: center; flex-wrap: wrap; }
  .tetris-side-right { order: 0; width: 100%; justify-content: center; }
  .tetris-layout { flex-direction: column; align-items: center; }
  .tetris-mini { flex-direction: row; }
  /* Panels stack under the well here, so the board column is ~1121px tall.
     Reserve it so content below the board does not jump on injection. */
  #board-wrap { min-height: var(--board-reserve-stacked, 1122px); }
}

/* ---- Mobile input & tap-target hardening ----
   iOS Safari auto-zooms when a focused form control has a font-size < 16px.
   Force 16px on phones so focusing a name/room/chat field never zooms the page.
   Also grow the smaller controls to a comfortable ~44px touch target. */
@media (max-width: 768px) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]),
  select, textarea { font-size: 16px !important; }
  .game-buttons .btn-felt { min-height: 44px; padding-top: .6rem; padding-bottom: .6rem; }
  .mode-tab { padding-top: .55rem; padding-bottom: .55rem; }
  .rating-star { font-size: 1.7rem; padding: .1rem .2rem; }
  .faq-acc-item summary { padding-top: 1rem; padding-bottom: 1rem; }
}

/* ---- No drop shadows on content boxes, cards, panels and tables (per request) ---- */
.card, .variant-card, .variant-card:hover,
.howto-card, .tetris-box, .mp-panel, .mp-player,
.stats-strip .ss-item, .rating-widget, .game-shell,
.facts-table, .data-table, .lb-table, .game-content table,
.tetris-mini .tm-row, .faq-acc-item {
  box-shadow: none;
}

/* ---- Mobile: show the playable board first so users never scroll to play ----
   Flex `order` only changes VISUAL order; DOM order (H1 first) stays intact for SEO. */
@media (max-width: 768px) {
  .play-first { display: flex; flex-direction: column; }
  .play-first .home-play { order: -1; }
  .play-first .game-header { order: 0; }
  .play-first .page-intro { order: 1; margin-top: 1.25rem; }
}
