/* ---------- reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #06080c;
  color: #f4f4f5;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

:root { --app-max: 480px; }
.app { max-width: var(--app-max); margin: 0 auto; min-height: 100dvh; background: #0f1115; box-shadow: 0 0 80px rgba(0,0,0,.6); position: relative; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
.muted { color: #9aa0a6; }

:root {
  --accent: #ffb547;
  --accent-2: #ff8a3d;
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232732;
  --line: #2a2f3a;
  --ok: #56d49a;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: rgba(15,17,21,.92);
  backdrop-filter: saturate(160%) blur(10px);
  position: sticky; top: 0; z-index: 30;
  border-bottom: 1px solid var(--line);
}
.app .topbar { width: 100%; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: inset 0 0 0 2px rgba(0,0,0,.15);
}
.brand-name { font-weight: 800; letter-spacing: .2px; }
.streak-pill {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--panel); border: 1px solid var(--line);
  padding: 6px 10px; border-radius: 999px; font-size: 14px;
}
.streak-pill .flame { filter: drop-shadow(0 0 6px rgba(255,140,60,.6)); }

.play-meta { display: flex; gap: 6px; }
.chip {
  background: var(--panel); border: 1px solid var(--line);
  padding: 5px 9px; border-radius: 999px; font-size: 12px; letter-spacing: .3px;
}
.play-actions { display: flex; gap: 6px; }
.icon-btn {
  background: var(--panel); border: 1px solid var(--line);
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.icon-btn:active { transform: scale(.96); }
.icon-btn[disabled] { opacity: .35; cursor: not-allowed; pointer-events: none; }
.icon-btn svg { display: block; }

/* ---------- home ---------- */
main { padding: 16px; }
.daily-grid { grid-template-columns: 1fr 1fr 1fr; }
.hero h1 {
  font-size: clamp(28px, 6vw, 40px); line-height: 1.05;
  margin: 8px 0 6px; letter-spacing: -0.02em;
}
.hero .tag { color: #c5c8d0; margin: 0 0 16px; }

.upload-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 14px; display: grid; gap: 12px;
}
.upload-drop {
  display: block; border: 2px dashed #3a3f4d; border-radius: 14px;
  padding: 22px; text-align: center; transition: border-color .15s, background .15s;
  background: #15181f;
}
.upload-drop.dragover { border-color: var(--accent); background: #1c2030; }
.upload-inner { display: grid; gap: 4px; justify-items: center; color: #d6d8de; }
.upload-inner svg { color: var(--accent); }
.upload-inner strong { font-size: 16px; }

.upload-drop.has-image {
  background-size: cover; background-position: center;
  border-style: solid; border-color: transparent;
  min-height: 220px; padding: 0;
}
.upload-drop.has-image .upload-inner { display: none; }

.diff-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.diff {
  background: var(--panel-2); border: 1px solid var(--line); color: #f4f4f5;
  padding: 10px 6px; border-radius: 12px; display: grid; gap: 2px;
  font-size: 12px;
}
.diff b { font-size: 13px; }
.diff[aria-checked="true"] {
  background: linear-gradient(180deg, #2a2233, #2a1f1d);
  border-color: var(--accent); color: #fff;
  box-shadow: 0 0 0 2px rgba(255,181,71,.15) inset;
}

.btn-primary, .btn-secondary {
  border-radius: 12px; padding: 14px 16px; font-weight: 700;
  border: 1px solid transparent; width: 100%;
  display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: #1a1300;
}
.btn-primary:disabled { opacity: .5; filter: saturate(.4); cursor: not-allowed; }
.btn-secondary {
  background: var(--panel-2); color: #f4f4f5; border-color: var(--line);
}
.btn-secondary:disabled { opacity: .5; cursor: not-allowed; }

.daily { margin-top: 28px; }
.daily h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -0.01em; }
.daily-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-top: 12px; }
.daily-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  overflow: hidden; display: block; text-decoration: none; aspect-ratio: 3 / 4;
  position: relative; color: inherit;
}
.daily-card .thumb {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  filter: saturate(1.05);
}
.daily-card .scrim {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, transparent 40%, rgba(0,0,0,.78));
}
.daily-card .label {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; letter-spacing: .3px;
}
.daily-card .tier { font-weight: 800; text-transform: uppercase; }
.daily-card.solved .tier::after { content: " ✓"; color: var(--ok); }
.daily-card .pieces { color: #d6d8de; }

.footer {
  margin: 24px 0 0; padding: 0 16px 24px;
  display: flex; align-items: center; justify-content: space-between;
  color: #8b9099; font-size: 13px;
}
.footer a { color: #8b9099; text-decoration: underline; }

/* ---------- play page ---------- */
body.page-play {
  background: #0b0d12;
  height: 100dvh;
  height: 100svh;
  overflow: hidden;
  overscroll-behavior: none;
}
body.page-play .app {
  height: 100dvh;
  height: 100svh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.play-main {
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  flex: 1 1 0;
  min-width: 0;
  min-height: 0;
  width: 100%;
  overflow: hidden;
}

.board-wrap {
  position: relative;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  padding: 8px;
  background:
    radial-gradient(1200px 600px at 50% -200px, #1a1f2c 0%, transparent 60%),
    #0b0d12;
}

.board {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 14px;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.018) 0 6px, transparent 6px 12px),
    #0f1320;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
}
.board.panning { cursor: grabbing; }

/* Pan/zoom layer. All parked pieces and the frame outline live here. */
.board-content {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.board .ghost {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  max-width: 92%; max-height: 92%; border-radius: 12px; opacity: .14;
  pointer-events: none; user-select: none;
}

.board .frame-outline {
  position: absolute;
  border: 2px dashed rgba(255,255,255,.10);
  border-radius: 8px;
  pointer-events: none;
}

/* tray */
:root { --tray-h: 110px; }
.tray-wrap {
  position: relative;
  background: linear-gradient(180deg, #14171f, #0f1320);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}
.tray {
  display: flex; gap: 12px; align-items: center;
  overflow-x: auto; overflow-y: hidden;
  padding: 14px 18px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-x;
  scrollbar-width: thin;
  min-height: calc(var(--tray-h) + 28px);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overscroll-behavior: contain;
}
.tray::-webkit-scrollbar { height: 6px; }
.tray::-webkit-scrollbar-thumb { background: #2c3140; border-radius: 999px; }
.tray-edge {
  position: absolute; top: 0; bottom: 0; width: 24px; pointer-events: none; z-index: 2;
}
.tray-edge-left  { left: 0;  background: linear-gradient(90deg, #14171f, transparent); }
.tray-edge-right { right: 0; background: linear-gradient(270deg, #14171f, transparent); }

/* piece */
.piece {
  position: absolute;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
  /* No drop-shadow on board pieces — overlapping shadows would draw a dark
     seam between adjacent / merged pieces. The SVG edge stroke is enough
     to keep them visually distinct. */
}
.piece.in-tray {
  position: relative;
  flex: 0 0 auto;
  /* Constant tray size per puzzle: --tray-h is set by JS based on difficulty;
     --ar is each piece's intrinsic aspect ratio. */
  height: var(--tray-h);
  width: calc(var(--tray-h) * var(--ar, 1));
  /* Subtle lift only in the tray so pieces read against the tray surface. */
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.45));
}
.piece-placeholder {
  flex: 0 0 auto;
  background: rgba(255,255,255,.04);
  border: 1px dashed rgba(255,255,255,.10);
  border-radius: 10px;
  pointer-events: none;
}
.piece.dragging {
  z-index: 1000;
  /* No drop-shadow while dragging — the user explicitly didn't want the
     touchdown shadow. The lifted feel comes from being above other pieces. */
}
/* No filter override on .locked — keeps the same look as the rest. */
.piece svg {
  display: block;
  pointer-events: none;
  width: 100%;
  height: 100%;
  shape-rendering: geometricPrecision;
  overflow: visible;
}
.piece svg .edge {
  stroke: rgba(0,0,0,.55);
  stroke-width: 1.1;
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.piece svg .gloss {
  stroke: rgba(255,255,255,.16);
  stroke-width: 0.8;
  fill: none;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
}

/* win card */
.win-card {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade .25s ease both;
}
.win-card[hidden] { display: none; }
[hidden] { display: none !important; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.win-inner {
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 22px; max-width: 380px; width: 100%; text-align: center;
}
.win-inner h2 { margin: 0 0 4px; font-size: 28px; }
.win-actions { display: grid; gap: 8px; margin-top: 14px; }

/* The .piece-layer is a body-level overlay that hosts pieces while they're
   being dragged so they aren't clipped by the board's overflow:hidden. */
.piece-layer { position: fixed; inset: 0; pointer-events: none; z-index: 90; }
.piece-layer .piece { pointer-events: auto; }
