

/* The chrome (buttons, dialogs, chips, panels, text) follows the site-wide theme (platform/site.css, picked in the site
   bar); the skin's backgrounds, board and pieces stay its own. :root[data-ph-theme] outranks theme.css's :root. */
:root[data-ph-theme] {
  --ink: var(--ph-ink);
  --accent: var(--ph-accent);
  --pale: color-mix(in srgb, var(--ph-surface) 85%, transparent);
  --pale-solid: var(--ph-surface);
  --panel: color-mix(in srgb, var(--ph-surface) 70%, transparent);
  --btn-hover: var(--ph-surface-2);
  --tab-on: var(--ph-accent-soft);
  --line: color-mix(in srgb, var(--ph-ink) 50%, transparent);
  --line-soft: color-mix(in srgb, var(--ph-ink) 15%, transparent);
  --btn-shadow: color-mix(in srgb, var(--ph-ink) 35%, transparent);
  --toast-bg: var(--ph-ink);
  --toast-ink: var(--ph-surface);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--page-bg); color: var(--ink);
  font-family: var(--font-body); user-select: none; touch-action: manipulation; }
[hidden] { display: none !important; }
#app { position: fixed; inset: 0; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 12px max(10px, env(safe-area-inset-bottom));
  background-size: cover; background-position: center; overflow: hidden; }
.menu-bg { background-image: var(--bg-menu); }
.game-bg { background-image: var(--bg-game); }

h1, h2 { font-family: var(--font-display); margin: 0; font-weight: normal; letter-spacing: .02em; }
h1 { font-size: clamp(22px, 5vw, 34px); }

.panel { background: var(--panel); border-radius: 14px; box-shadow: 0 2px 8px var(--shadow); backdrop-filter: blur(2px); }

/* ---------------------------------------------------------------- buttons */
.btn { font: inherit; font-size: clamp(15px, 3.6vw, 20px); color: var(--ink); background: var(--pale-solid);
  border: 2px solid var(--line); border-radius: 12px; padding: 10px 14px; cursor: pointer;
  box-shadow: 0 3px 0 var(--btn-shadow); display: inline-flex; align-items: center; justify-content: center; gap: 10px; }
.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--btn-shadow); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.big { min-width: min(78vw, 360px); padding: 12px 18px; font-size: clamp(18px, 4.4vw, 24px); }
.btn.big img { height: 1.5em; width: auto; }
.btn.big small { display: block; font-size: .55em; font-weight: normal; opacity: .85; }
.btn.small { padding: 6px 12px; font-size: 15px; }
.play-btn { width: min(38vw, 160px); aspect-ratio: 1; border: 0; cursor: pointer; background: var(--play-btn-bg);
  filter: drop-shadow(0 3px 4px var(--shadow)); font: inherit; font-size: clamp(20px, 5vw, 28px); font-family: var(--font-display); color: var(--play-btn-ink); }
.play-btn:active { transform: scale(.96); }

/* ---------------------------------------------------------------- menu */
#screen-menu { justify-content: space-between; }
.logo { width: min(70vw, 44vh, 380px); margin-top: 2vh; filter: drop-shadow(0 4px 6px var(--shadow)); }
.menu-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.credit img { height: 44px; opacity: .85; }
@media (orientation: landscape) and (max-height: 520px) {
  #screen-menu { flex-direction: row; justify-content: space-around; }
  .logo { width: min(40vw, 70vh); }
  .credit { display: none; }
  .menu-buttons { gap: 8px; }
}

.topbar { width: 100%; max-width: 640px; display: grid; grid-template-columns: 90px 1fr 90px; align-items: center; text-align: center; padding: 4px 0 10px; }
.topbar .btn { justify-self: start; }
.topbar h1 { background: var(--pale); border-radius: 14px; padding: 2px 14px; justify-self: center; box-shadow: 0 2px 6px var(--shadow); }

.mode-picker { display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; max-width: 640px; flex: 1; }
.mode-card { flex: 1; text-align: center; padding: 12px; background: var(--panel); border-radius: 18px; max-width: 420px; }
.mode-card img { width: min(60vw, 300px); max-height: 32vh; object-fit: contain; }
.mode-card h2 { font-size: clamp(24px, 6vw, 36px); margin: 6px 0; }
.mode-card p { margin: 0; font-size: clamp(14px, 3.4vw, 18px); line-height: 1.35; }
.arrow { background: var(--pale); border: 0; border-radius: 50%; cursor: pointer; padding: 8px; width: 48px; height: 48px; flex: none; box-shadow: 0 2px 5px var(--shadow); }
.arrow img { width: 100%; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .35)); }
#mode-play { margin: 12px 0 8px; }

/* ---------------------------------------------------------------- game */
#screen-game { padding: max(6px, env(safe-area-inset-top)) 8px max(6px, env(safe-area-inset-bottom)); }
.toolbar { display: flex; gap: 6px; padding: 6px; width: 100%; max-width: 720px; }
.toolbar .btn { flex: 1; padding: 8px 4px; font-size: clamp(13px, 3.3vw, 18px); }
.play { flex: 1; width: 100%; max-width: 720px; display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 6px; min-height: 0; }
.score-panel { display: flex; gap: 12px; padding: 4px 20px; justify-content: space-around; width: min(100%, 420px); text-align: center; }
.score-panel div { display: flex; flex-direction: column; line-height: 1.1; }
.score-panel small { font-size: 12px; opacity: .75; }
.score-panel strong { font-size: clamp(20px, 5vw, 28px); font-weight: bold; font-variant-numeric: tabular-nums; }
.board-wrap { flex: 1; width: 100%; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board { position: relative; }
.bonuses { display: flex; gap: 6px; padding: 4px 8px; flex-wrap: wrap; justify-content: center; max-width: 100%; min-height: 54px; }
.bonus { position: relative; width: 48px; text-align: center; font-size: 12px; line-height: 1; font-weight: bold; cursor: pointer; }
.bonus img { width: 36px; height: 38px; object-fit: contain; display: block; margin: 0 auto 2px; }
.bonus.size-1 img { transform: scale(.7); } .bonus.size-3 img { transform: scale(1.1); } .bonus.size-5 img { transform: scale(1.2); }
.bonuses .none { align-self: center; font-size: 14px; opacity: .8; padding: 6px; }

.pause { width: min(100%, 460px); margin-top: 12px; padding: 14px; text-align: center; max-height: 100%; overflow: auto; }
.pause .btn { margin-top: 12px; }

/* board cells */
.cell, .edge { position: absolute; display: flex; align-items: center; justify-content: center; will-change: transform; }
.cell { padding: 0; }
.cell .bg { position: absolute; inset: 7%; border-radius: 10%; background: var(--cell-bg); box-shadow: inset 0 0 0 1px var(--cell-edge); }
.cell img, .edge img { position: relative; width: 76%; height: 76%; object-fit: contain; pointer-events: none; transition: opacity .15s, transform .25s; transform: scale(var(--s, 1)); }
.cell.selected img, .edge.selected img { opacity: .5; transform: scale(calc(var(--s, 1) * 1.08)); }
.cell.selected .bg, .edge.selected .bg { background: var(--cell-selected); }
.edge { transition: left .32s ease, top .32s ease, opacity .25s; }
.edge.off { opacity: 0; pointer-events: none; }
.edge .bg { position: absolute; inset: 17%; border-radius: 12%; }
.edge.vanish .bg { border: 2px solid var(--vanish-line); }
.edge img { width: 54%; height: 54%; }
.cell .ghost { position: absolute; width: 76%; height: 76%; object-fit: contain; filter: brightness(0) opacity(.28); }
.cell.pop img { animation: pop .5s ease-out; }
.cell.pop-final img { animation: pop 1s ease-out; }
.cell.spin img { animation: spin .5s ease-out; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(var(--s, 1)); } }
@keyframes spin { from { transform: rotate(360deg) scale(var(--s, 1)); } to { transform: rotate(0) scale(var(--s, 1)); } }
.no-anim .cell img, .no-anim .edge, .no-anim .edge img, .no-anim .modal-back, .no-anim .tutorial-circles img { animation: none !important; transition: none !important; }

/* ---------------------------------------------------------------- lists, settings, help */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-bottom: 8px; }
.tabs .btn[aria-pressed="true"] { background: var(--tab-on); border-color: var(--accent); }
.list, .settings, .help { width: min(100%, 640px); padding: 12px 14px; overflow: auto; flex: 0 1 auto; max-height: calc(100% - 90px); }
.list ol { margin: 0; padding: 0; list-style: none; }
.list li { display: grid; grid-template-columns: 2em 1fr auto; gap: 8px; padding: 7px 4px; border-bottom: 1px solid var(--line-soft); align-items: baseline; }
.list li small { display: block; opacity: .7; }
.list li b { font-variant-numeric: tabular-nums; }
.list .empty { text-align: center; padding: 18px; opacity: .75; }
.settings { display: flex; flex-direction: column; gap: 14px; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 18px; }
.settings .check { flex-direction: row; align-items: center; gap: 10px; }
.settings input[type=range] { width: 100%; accent-color: var(--accent); }
.settings input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.help h3 { font-family: var(--font-display); font-weight: normal; margin: 14px 0 4px; font-size: 22px; }
.help h3:first-child { margin-top: 0; }
.help p { margin: 4px 0; line-height: 1.4; }
.help p.help-replay { margin-top: 12px; }
.help .btn { margin: 6px 6px 0 0; }
.piece-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 6px; }
.piece-list div { display: flex; gap: 8px; align-items: center; font-size: 14px; }
.piece-list img { width: 42px; height: 44px; object-fit: contain; }

/* ---------------------------------------------------------------- modal */
#modal-root { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.modal-back { position: absolute; inset: 0; background: var(--scrim); display: flex; align-items: center; justify-content: center; padding: 12px; pointer-events: auto; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--pale-solid); border-radius: 16px; padding: 16px; width: min(100%, 460px); max-height: 100%; overflow: auto; box-shadow: 0 8px 30px var(--shadow-lg); }
.modal h2 { text-align: center; font-size: 28px; margin-bottom: 8px; }
.modal .actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.modal input[type=text] { width: 100%; font: inherit; font-size: 20px; padding: 8px 10px; border-radius: 10px; border: 2px solid var(--line); }
.modal p { text-align: center; }
.summary { width: 100%; border-collapse: collapse; font-size: 16px; }
.summary th { text-align: left; font-weight: bold; font-family: var(--font-display); font-size: 18px; padding-top: 8px; }
.summary td { padding: 3px 4px; }
.summary td:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.summary tr.total td { font-weight: bold; border-top: 2px solid var(--line); padding-top: 6px; }
.summary tr.neg td:last-child { color: var(--neg); }

/* ---------------------------------------------------------------- tutorial overlay */
.tutorial { position: absolute; inset: 0; z-index: 10; pointer-events: none; }
.tutorial-circles img { position: absolute; pointer-events: none; filter: var(--hl-filter); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.12); } }
.tutorial-card { position: absolute; left: 50%; transform: translateX(-50%); width: min(92%, 440px); padding: 10px 14px; pointer-events: auto;
  background: var(--pale-solid); border: 2px solid var(--line); }
.tutorial-card.top { top: 112px; } .tutorial-card.bottom { bottom: 84px; }
.tutorial-card small { opacity: .7; }
.tutorial-card p { margin: 4px 0 8px; font-size: 18px; line-height: 1.3; white-space: pre-line; }
.tutorial-actions { display: flex; justify-content: space-between; gap: 8px; }

/* ---------------------------------------------------------------- short landscape screens: board left, controls right */
@media (orientation: landscape) and (max-height: 560px) {
  #screen-game { display: grid; grid-template-columns: 1fr 200px; grid-template-rows: auto auto 1fr; gap: 6px 10px; align-items: start; justify-items: stretch; }
  .play { display: contents; }
  .board-wrap { grid-column: 1; grid-row: 1 / span 3; height: 100%; }
  .toolbar { grid-column: 2; grid-row: 1; display: grid; grid-template-columns: 1fr 1fr; max-width: none; }
  .score-panel { grid-column: 2; grid-row: 2; width: auto; padding: 4px 8px; }
  .bonuses { grid-column: 2; grid-row: 3; align-self: start; justify-self: center; }
  .pause { grid-column: 1 / -1; grid-row: 1 / -1; justify-self: center; align-self: center; }
  .tutorial-card { width: min(60%, 440px); }
  .tutorial-card.top { top: 8px; } .tutorial-card.bottom { bottom: 8px; }
}
