/* Spider Solitaire. Cards are placed by game.js (absolute, transform only); this file draws them and lays out the bar,
   the tools and the dialogs. Portrait: bar on top, tools at the bottom. Landscape: both in a rail on the left. */
:root {
  --felt: #1d2763; --felt-edge: #10173d; --ink: #1d1a3a; --red: #d42a46; --violet: #4b3bf0; --deep: #2a1d9e;
  --mint: #5ff2c8; --star: #ffb020; --rail: clamp(132px, 16vw, 196px);
  --card-font: "Arial Narrow", "Roboto Condensed", "Helvetica Neue", Arial, system-ui, sans-serif;
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--felt-edge); }
body { font-family: var(--ui-font); color: #fff; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
#app {
  position: relative; width: 100vw; height: 100vh; height: 100dvh; overflow: hidden; user-select: none; -webkit-user-select: none;
  background: radial-gradient(120% 90% at 50% 35%, #2a3680 0, var(--felt) 45%, var(--felt-edge) 100%);
  display: flex; flex-direction: column; justify-content: space-between;
}
.loading { margin: auto; color: #d8d6ff; font-size: 15px; }

/* The bar and the tools */
.bar {
  position: relative; z-index: 3000; display: flex; align-items: center; gap: 6px; min-height: 46px;
  padding: max(5px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 5px max(8px, env(safe-area-inset-left));
}
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px; border: 0; border-radius: 16px; cursor: pointer;
  background: rgb(255 255 255 / .13); font-size: 13px; font-weight: 700; white-space: nowrap;
}
.chip span { font-size: 10px; opacity: .8; }
.chip:hover { background: rgb(255 255 255 / .2); }
.title { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.moves { font-size: 12px; color: #c9c6f5; white-space: nowrap; font-variant-numeric: tabular-nums; }
.moves strong { color: #fff; font-size: 15px; }
.moves .target { color: #a9a5e8; margin-left: 1px; }
.bar-actions { display: flex; gap: 2px; }
.icon { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 12px; background: transparent; cursor: pointer; }
.icon:hover { background: rgb(255 255 255 / .12); }
.icon svg, .tool svg, .button svg { width: 20px; height: 20px; }
.tools {
  position: relative; z-index: 3000; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 6px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
}
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; min-height: 50px; border: 0; border-radius: 14px;
  background: rgb(255 255 255 / .1); cursor: pointer; font-size: 12px; font-weight: 700; position: relative;
}
.tool small { font-size: 10px; font-weight: 600; color: #c9c6f5; }
.tool:hover:not(:disabled) { background: rgb(255 255 255 / .18); }
.tool:disabled { opacity: .38; cursor: default; }
.tool.nudge { animation: nudge 1.6s ease-in-out infinite; }
@keyframes nudge { 50% { background: rgb(95 242 200 / .3); box-shadow: 0 0 0 3px rgb(95 242 200 / .25); } }
button:focus-visible, .card:focus-visible { outline: 3px solid var(--mint); outline-offset: 2px; }

#app.landscape { display: block; }
#app.landscape .bar, #app.landscape .tools { position: absolute; left: 0; width: var(--rail); }
#app.landscape .bar { top: 0; flex-wrap: wrap; justify-content: space-between; padding: max(8px, env(safe-area-inset-top)) 8px 4px max(8px, env(safe-area-inset-left)); gap: 4px 2px; }
#app.landscape .chip { order: 1; flex: 1 1 100%; justify-content: center; }
#app.landscape .title { order: 2; flex: 1 1 100%; text-align: left; font-size: 14px; padding-left: 2px; }
#app.landscape .moves { order: 3; padding-left: 2px; }
#app.landscape .bar-actions { order: 0; flex: 1 1 100%; justify-content: flex-end; }
#app.landscape .tools { bottom: 0; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 6px 6px max(8px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left)); }
#app.landscape .tool { min-height: 54px; font-size: 11px; border-radius: 12px; }
#app.landscape::before { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--rail); background: rgb(6 8 30 / .22); box-shadow: inset -1px 0 rgb(255 255 255 / .06); }

/* The table and the cards */
.table { position: absolute; inset: 0; touch-action: none; }
.col-slot, .found-slot, .stock {
  position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch); transform-origin: 0 0;
  border-radius: calc(var(--cw) * .1); border: 1.5px dashed rgb(255 255 255 / .16);
}
.col-slot.empty { border-color: rgb(255 255 255 / .34); background: rgb(255 255 255 / .05); }
.found-slot { border-style: solid; border-color: rgb(255 255 255 / .1); background: rgb(0 0 0 / .12); }
.stock { z-index: 200; padding: 0; background: transparent; cursor: pointer; }
.stock:disabled { cursor: default; }
.stock .count {
  position: absolute; right: -6px; top: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; display: grid; place-items: center;
  background: #fff; color: var(--deep); font: 800 11px/1 var(--ui-font); box-shadow: 0 1px 3px rgb(0 0 0 / .4);
}
.stock .count:empty { display: none; }
.stock.hint-dst { border-style: solid; border-color: var(--mint); box-shadow: 0 0 0 2px var(--mint), 0 0 18px 4px rgb(95 242 200 / .55); }
.card { position: absolute; left: 0; top: 0; width: var(--cw); height: var(--ch); transform-origin: 0 0; outline-offset: 1px; border-radius: calc(var(--cw) * .1); }
.card.movable { cursor: grab; }
.card.flying { z-index: 5000 !important; }
.card.lifted { z-index: 6000 !important; cursor: grabbing; }
.in { position: relative; width: 100%; height: 100%; }
.face, .back { position: absolute; inset: 0; border-radius: calc(var(--cw) * .1); }
.face { background: #fffdf8; box-shadow: 0 1px 2px rgb(5 4 30 / .5), inset 0 0 0 1px rgb(30 24 80 / .12); overflow: hidden; transition: background-color .2s; }
.face.red { color: var(--red); }
.face.black { color: var(--ink); }
.back {
  opacity: 0;
  background:
    repeating-linear-gradient(45deg, rgb(255 255 255 / .13) 0 1.5px, transparent 1.5px 6px),
    repeating-linear-gradient(-45deg, rgb(255 255 255 / .13) 0 1.5px, transparent 1.5px 6px),
    linear-gradient(160deg, #6a5cff, var(--violet) 55%, #3a2cc9);
  box-shadow: 0 1px 2px rgb(5 4 30 / .55), inset 0 0 0 max(1.5px, calc(var(--cw) * .045)) #f4f2ff;
}
.card.down .back { opacity: 1; }
.ix { position: absolute; left: calc(var(--cw) * .07); top: calc(var(--rf) * .08); display: flex; align-items: baseline; font: 800 var(--rf)/1 var(--card-font); font-stretch: condensed; letter-spacing: -.02em; }
.ix b { font-weight: 800; }
.ix b.ten { letter-spacing: -.12em; margin-right: .08em; }
.ix i { font-style: normal; font-size: .84em; margin-left: .04em; }
.pip { position: absolute; left: 50%; bottom: 7%; transform: translateX(-50%); font: calc(var(--cw) * .58)/1 var(--ui-font); }
.card.dim .face { background: #d9d8e6; }
.card.dim .pip { opacity: .3; }
.card.lifted .face { box-shadow: 0 12px 24px rgb(0 0 0 / .45), inset 0 0 0 1px rgb(30 24 80 / .12); }
.card.hint-src .face, .card.hint-dst .face, .col-slot.hint-dst { box-shadow: 0 0 0 2px var(--mint), 0 0 16px 3px rgb(95 242 200 / .6); }
.col-slot.hint-dst { border-color: var(--mint); }
.card.drop-ok .face, .col-slot.drop-ok { box-shadow: 0 0 0 2px #fff, 0 0 14px 3px rgb(255 255 255 / .45); }
.col-slot.drop-ok { border-color: #fff; }

/* The status line: one see-through sentence that fades by itself */
.note {
  position: absolute; z-index: 4000; left: 50%; bottom: 76px; transform: translate(-50%, 6px); max-width: min(92%, 520px); width: max-content;
  padding: 7px 14px; border-radius: 14px; background: rgb(8 6 36 / .62); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  font-size: 13px; line-height: 1.35; text-align: center; color: #fff; pointer-events: none; opacity: 0; transition: opacity .35s, transform .35s;
}
.note.shown { opacity: 1; transform: translate(-50%, 0); }
.note.warn { color: #ffe0e5; }
.note.tip { color: #e6fff7; }
#app.landscape .note { left: calc(var(--rail) + (100% - var(--rail)) / 2); bottom: 12px; }

/* Effects */
.fx { position: fixed; inset: 0; z-index: 7000; pointer-events: none; overflow: hidden; }
.sparks { position: absolute; width: 0; height: 0; }
.sparks i { position: absolute; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 2px; }
.praise {
  position: absolute; display: flex; flex-direction: column; align-items: center; padding: 6px 16px 7px; border-radius: 18px;
  background: radial-gradient(closest-side, rgb(10 8 40 / .5), rgb(10 8 40 / .18) 70%, transparent); color: #fff; text-align: center; white-space: nowrap;
}
.praise strong { font: 900 20px/1.1 var(--ui-font); letter-spacing: .01em; text-shadow: 0 2px 10px rgb(0 0 0 / .45), 0 0 1px var(--deep); }
.praise span { font-size: 12px; font-weight: 700; color: #d9fff3; }
.praise.big strong { font-size: 26px; color: #fff6dc; text-shadow: 0 0 14px rgb(255 176 32 / .7), 0 2px 10px rgb(0 0 0 / .5); }
.cascade { position: absolute; inset: 0; z-index: 6500; width: 100%; height: 100%; pointer-events: none; }

/* Dialogs */
dialog {
  border: 0; border-radius: 22px; background: #f7f6ff; color: #231c5a; padding: 22px; width: min(400px, calc(100% - 24px));
  max-height: calc(100% - 20px); overflow: auto; box-shadow: 0 24px 70px rgb(4 3 30 / .6); text-align: center;
}
dialog::backdrop { background: rgb(9 8 40 / .62); backdrop-filter: blur(4px); }
dialog h2 { font: 900 24px/1.15 var(--ui-font); margin: 4px 0 10px; outline: none; }
dialog p { font-size: 15px; line-height: 1.5; color: #4a4580; margin: 6px 0; }
dialog .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.button {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px; border-radius: 14px; cursor: pointer;
  border: 1.5px solid #d9d6f5; background: #fff; color: #2b2470; font-weight: 700; font-size: 15px;
}
.button:hover { background: #efedff; }
.button.primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.button.primary:hover { background: #3c2de0; }
.button.play { background: #ffd23f; border: 2px solid var(--deep); color: var(--deep); font-weight: 800; box-shadow: 0 4px 0 #f6b42c; }
.button.play:hover { background: #ffdc66; }
.button.quiet { border-color: transparent; background: transparent; color: #6c67a5; }
dialog button:focus-visible { outline-color: var(--violet); }
.menu .actions { margin-top: 4px; }
.menu .button { justify-content: flex-start; }
.menu .button.quiet { justify-content: center; }
.choices { display: grid; gap: 10px; }
.choice {
  position: relative; display: grid; gap: 2px; text-align: left; padding: 12px 14px; border-radius: 16px; border: 2px solid #dcd9f6; background: #fff; cursor: pointer;
}
.choice strong { font-size: 17px; color: #231c5a; }
.choice span { font-size: 13px; color: #5d5895; }
.choice.current { border-color: var(--violet); box-shadow: 0 0 0 3px rgb(75 59 240 / .15); }
.choice .suit-sample { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); font-size: 26px; color: var(--ink); letter-spacing: 2px; }
.choice .suit-sample em { font-style: normal; color: var(--red); }
.help ul.rules { text-align: left; padding-left: 20px; margin: 8px 0; color: #3e3974; font-size: 15px; line-height: 1.45; }
.help ul.rules li { margin: 6px 0; }
.help .keys { font-size: 13px; color: #6c67a5; }
.rule-sample { display: flex; justify-content: center; margin: 4px 0 8px; }
.rule-sample .mini {
  width: 54px; height: 76px; margin-left: -20px; padding: 4px 0 0 4px; text-align: left; border-radius: 6px; background: #fff; letter-spacing: -1px;
  box-shadow: 0 1px 3px rgb(20 10 80 / .35); font: 800 17px/1 var(--card-font);
}
.rule-sample .mini:first-child { margin-left: 0; }
.rule-sample .mini.red { color: var(--red); }
.rule-sample .mini.black { color: var(--ink); }
.results[open] { display: flex; flex-direction: column; }
.results .result-mipo { order: -1; width: 76px; margin: -2px auto 2px; }
.results .result-mipo svg { width: 100%; height: auto; display: block; }
.results h2 { margin-bottom: 2px; }
.results p.result-sub { margin: 0 0 8px; font-weight: 700; color: #4a4580; }
ul.stars { list-style: none; display: flex; justify-content: center; gap: 8px; padding: 0; margin: 6px 0 10px; }
ul.stars li { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 33%; font-size: 12px; font-weight: 700; color: #8f8bb8; }
ul.stars .star { font-size: 34px; line-height: 1; color: #d8d6ea; }
ul.stars li.pop .star { color: var(--star); text-shadow: 0 2px 0 #d98a00; animation: star-pop .5s ease-out; }
ul.stars li.pop { color: #4a3d00; color: #5b4a12; }
@keyframes star-pop { 0% { transform: scale(.2) rotate(-30deg); } 60% { transform: scale(1.35) rotate(8deg); } 100% { transform: scale(1); } }
.result-stats { display: flex; justify-content: center; gap: 28px; margin: 4px 0 6px; }
.result-stats div { display: flex; flex-direction: column; }
.result-stats strong { font-size: 24px; font-variant-numeric: tabular-nums; }
.result-stats span { font-size: 12px; color: #6c67a5; text-transform: uppercase; letter-spacing: .05em; }
p.result-note { font-weight: 700; color: #2b2470; margin: 4px 0; }
p.daily-rank { color: #4b3bf0; }
.star-total { font-size: 16px; }
.star-total span { color: var(--star); }
.table-wrap { overflow-x: auto; }
table.stats { border-collapse: collapse; width: 100%; font-size: 13px; color: #2b2470; font-variant-numeric: tabular-nums; }
table.stats th, table.stats td { padding: 6px 5px; border-bottom: 1px solid #e3e1f7; white-space: nowrap; }
table.stats thead th { font-size: 11px; color: #6c67a5; font-weight: 700; }
table.stats tbody th { text-align: left; }
.stats-dialog { width: min(640px, calc(100% - 24px)); }

@media (max-width: 380px) {
  .chip { padding: 0 8px; font-size: 12px; }
  .title { font-size: 14px; }
  .moves .label { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .note, .face { transition: none; }
  .tool.nudge { animation: none; box-shadow: 0 0 0 3px rgb(95 242 200 / .35); }
}
