/* ===== Spider Solitaire ===== */
:root {
  --card-w: 80px;
  --card-h: 112px;
  --col-gap: 11px;
  --felt-a: #0d6b39;
  --felt-b: #084d28;
  --chrome: #263a2c;
  --chrome-hi: #34503b;
  --gold: #e8c66b;
  --ink: #eef3ee;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  color: var(--ink);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
}
body {
  display: flex; flex-direction: column;
  background:
    radial-gradient(ellipse at 50% 0%, var(--felt-a), var(--felt-b) 70%),
    var(--felt-b);
}

/* ===== Topbar (menu + toolbar) ===== */
#topbar {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(180deg, var(--chrome-hi), var(--chrome));
  border-bottom: 1px solid #00000055;
  padding: 4px 10px; flex: 0 0 auto;
  box-shadow: 0 2px 6px #00000040;
  z-index: 50;
}
#menubar { display: flex; gap: 2px; }
.menu { position: relative; }
.menu-btn {
  background: none; border: 0; color: var(--ink);
  font-size: 14px; padding: 6px 12px; border-radius: 5px; cursor: pointer;
}
.menu-btn:hover, .menu.open .menu-btn { background: #ffffff22; }
.menu-list {
  display: none; position: absolute; top: 100%; left: 0; margin-top: 4px;
  background: #f6f6f4; color: #222; min-width: 220px; padding: 5px;
  border-radius: 8px; box-shadow: 0 10px 30px #0009; z-index: 100;
}
.menu.open .menu-list { display: block; }
.menu-list button {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  background: none; border: 0; text-align: left; font-size: 13.5px;
  padding: 8px 10px; border-radius: 5px; cursor: pointer; color: #222;
}
.menu-list button:hover { background: #1a7a45; color: #fff; }
.menu-list .key { font-size: 11px; opacity: .6; margin-left: 18px; }
.menu-list .tag { font-size: 11px; opacity: .6; }
.menu-list .sep { height: 1px; background: #0002; margin: 5px 4px; }
.submenu-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; opacity: .5; padding: 4px 10px 2px; }

#toolbar { display: flex; gap: 6px; margin-left: auto; }
.tbtn {
  background: linear-gradient(180deg, #f7f7f5, #e2e2dd);
  color: #223; border: 1px solid #0003; border-radius: 6px;
  padding: 6px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: 0 1px 2px #0003;
}
.tbtn:hover { background: linear-gradient(180deg, #fff, #ecece6); }
.tbtn:active { transform: translateY(1px); }
.tbtn:disabled { opacity: .45; cursor: default; }

/* ===== Board ===== */
#board { position: relative; flex: 1 1 auto; overflow: auto; padding: 8px 6px 4px; }
#top-row { display: flex; justify-content: space-between; align-items: flex-start;
  padding: 0 6px 6px; min-height: calc(var(--card-h) * .5); }
body.left-handed #top-row { flex-direction: row-reverse; }

#completed { display: flex; gap: 2px; flex-wrap: wrap; max-width: 60%; }
#stock { position: relative; height: calc(var(--card-h) * .6); width: calc(var(--card-w) + 40px); cursor: pointer; }
#stock.disabled { cursor: default; opacity: .8; }
.mini-card {
  position: absolute; top: 0; width: calc(var(--card-w) * .5); height: calc(var(--card-h) * .5);
  filter: drop-shadow(0 1px 2px #0006);
}
#completed .mini-card { position: static; }
.mini-card.done { animation: pop .3s ease; }
.mini-card svg { width: 100%; height: 100%; display: block; }
#stock:hover:not(.disabled) .mini-card:last-child { transform: translateY(-3px); }

#tableau {
  position: relative; display: flex; gap: var(--col-gap);
  padding: 0 6px; align-items: flex-start;
}
.column {
  position: relative; flex: 0 0 var(--card-w); width: var(--card-w);
  min-height: var(--card-h); border-radius: 8px;
}
.column.empty {
  outline: 2px dashed #ffffff44; outline-offset: -2px;
  background: #ffffff0d;
}
.column.drop-target { background: #ffe98a33; outline: 2px solid var(--gold); outline-offset: -2px; }
.column.hint-empty { animation: hintGlow 1.2s ease; }
.column.shake { animation: shake .35s; }

.card {
  position: absolute; left: 0; width: 100%; height: var(--card-h);
  transition: top .18s ease, left .18s ease;
  will-change: top;
}
body.no-anim .card { transition: none; }
.card .card-svg, .card svg { width: 100%; height: 100%; display: block;
  filter: drop-shadow(0 2px 3px #0005); border-radius: 8px; }
.card.movable { cursor: grab; }
.card.movable:active { cursor: grabbing; }
.card.dragging { transition: none; }
.card.hint .card-svg { animation: hintCard 1.2s ease; }
.card.removing { animation: removeCard .26s ease forwards; }
.card.flying {
  transition: transform 1.15s cubic-bezier(.4,0,1,.7), opacity .3s ease 1s;
  transform: translate(var(--fx), var(--fy)) rotate(var(--fr));
  opacity: 0; pointer-events: none; z-index: 5000;
}

#drag-layer { position: absolute; top: 0; left: 0; width: var(--card-w); height: 0;
  pointer-events: none; z-index: 9999; }
#drag-layer .card { transition: none; }
#drag-layer.outline .card .card-svg { opacity: .25; outline: 2px solid #fff; }

/* ===== Status bar ===== */
#statusbar {
  flex: 0 0 auto; display: flex; gap: 22px; align-items: center;
  background: linear-gradient(180deg, var(--chrome-hi), var(--chrome));
  padding: 6px 16px; font-size: 13px; border-top: 1px solid #0006;
}
#statusbar .stat b { color: var(--gold); font-variant-numeric: tabular-nums; }
#statusbar .muted { opacity: .6; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 54px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #111c; color: #fff; padding: 10px 18px; border-radius: 20px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 4000;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Dialogs ===== */
#overlay { position: fixed; inset: 0; background: #0008; display: none; z-index: 1000; }
#overlay.show { display: block; }
.dialog {
  display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: #f6f6f4; color: #222; border-radius: 12px; padding: 22px 24px;
  width: min(92vw, 380px); box-shadow: 0 20px 60px #000a; z-index: 1001;
}
.dialog.wide { width: min(94vw, 620px); }
.dialog.show { display: block; animation: dlgIn .18s ease; }
.dialog h2 { margin: 0 0 12px; font-size: 20px; color: #14532d; }
.dialog p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; }
.dialog .muted { opacity: .6; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.dialog button {
  padding: 9px 16px; border-radius: 7px; border: 1px solid #0002; cursor: pointer;
  font-size: 14px; font-weight: 600; background: #e8e8e4; color: #223;
}
.dialog button:hover { background: #dcdcd6; }
.dialog button.primary { background: #1a7a45; color: #fff; border-color: #14532d; }
.dialog button.primary:hover { background: #15683b; }
#select-input, .dialog input[type=number] {
  width: 100%; padding: 10px; font-size: 16px; border-radius: 7px; border: 1px solid #0003;
}

.diff-choices { display: grid; gap: 10px; }
.diff-choices button, .win-diff, #win-diff-btn { display: flex; flex-direction: column; align-items: center; padding: 14px; }
.diff-choices .big { font-size: 17px; color: #14532d; }
.diff-choices button span:last-child { font-size: 12px; opacity: .6; }

.opt { display: flex; align-items: center; gap: 10px; padding: 7px 2px; font-size: 14px; cursor: pointer; }
.opt input { width: 17px; height: 17px; }
.opt-group { margin-top: 12px; }
.opt-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; color: #14532d; }
.backs { display: flex; gap: 12px; }
.backs label { cursor: pointer; }
.backs input { display: none; }
.swatch { display: block; width: 40px; height: 56px; border-radius: 6px; border: 2px solid transparent; }
.backs input:checked + .swatch { border-color: #14532d; box-shadow: 0 0 0 2px #1a7a4555; }
.swatch.blue { background: repeating-linear-gradient(45deg, #1c4fa0, #1c4fa0 6px, #3b6fc4 6px, #3b6fc4 12px); }
.swatch.red { background: repeating-linear-gradient(45deg, #9c1f2b, #9c1f2b 6px, #c24651 6px, #c24651 12px); }
.swatch.green { background: repeating-linear-gradient(45deg, #1d6b45, #1d6b45 6px, #3a8f63 6px, #3a8f63 12px); }
.swatch.purple { background: repeating-linear-gradient(45deg, #4a2c73, #4a2c73 6px, #6e4a9e 6px, #6e4a9e 12px); }

.stats-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.stats-table th, .stats-table td { padding: 8px 6px; text-align: center; border-bottom: 1px solid #0001; }
.stats-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; opacity: .6; }
.stats-table td:first-child, .stats-table th:first-child { text-align: left; font-weight: 600; }

.win-stats { list-style: none; padding: 0; margin: 8px 0; display: flex; gap: 22px; justify-content: center; }
.win-stats b { color: #14532d; font-size: 20px; display: block; }
.win-line { text-align: center; }
.help-body ul { padding-left: 20px; }
.help-body li { margin: 6px 0; font-size: 13.5px; line-height: 1.45; }

/* ===== Keyframes ===== */
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-6px)} 40%{transform:translateX(6px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
@keyframes hintCard { 0%,100%{filter:drop-shadow(0 2px 3px #0005)} 50%{filter:drop-shadow(0 0 10px #ffe98a) drop-shadow(0 0 4px #ffe98a)} }
@keyframes hintGlow { 0%,100%{background:#ffffff0d} 50%{background:#ffe98a55} }
@keyframes removeCard { to { transform: scale(.6) translateY(-30px); opacity: 0; } }
@keyframes pop { 0%{transform:scale(.4);opacity:0} 100%{transform:scale(1);opacity:1} }
@keyframes dlgIn { from{transform:translate(-50%,-46%);opacity:0} to{transform:translate(-50%,-50%);opacity:1} }

@media (max-width: 560px) {
  #toolbar .tbtn { padding: 6px 10px; }
  #statusbar { gap: 14px; font-size: 12px; padding: 5px 10px; }
  .menu-btn { padding: 6px 8px; }
}
