* { box-sizing: border-box; }

:root {
  --felt-a: #1f7d3f;
  --felt-b: #0e4a25;
  --tile: #f7f4ea;
  --tile-edge: #cfc9b4;
  --ink: #2a2a2a;
  --accent: #2e9d54;
  --accent-dark: #17703a;
}

html, body {
  margin: 0; height: 100%;
  background: var(--felt-b);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #fff;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

#app {
  position: relative;
  height: 100vh; height: 100dvh;
  max-width: 520px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 12px max(14px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 35%, var(--felt-a), var(--felt-b) 85%);
  overflow: hidden;
}

/* ---------- top bar ---------- */
#topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex: 0 0 auto; }
.pill {
  display: flex; align-items: center; gap: 8px;
  min-width: 76px; height: 38px; padding: 0 14px;
  background: rgba(0, 0, 0, .38); border-radius: 19px;
  font-weight: 700; font-size: 17px;
}
.pill.mid { flex: 1; justify-content: center; max-width: 150px; font-size: 15px; letter-spacing: .5px; }
.ico { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.ico.fill { fill: #fff; stroke: none; }
.ico.star { fill: #ffc531; stroke: none; }

/* ---------- crossword grid ---------- */
#gridWrap { flex: 1 1 0; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 4px 0; }
#grid { display: grid; gap: var(--gap, 4px); }

.cell {
  width: var(--cs); height: var(--cs);
  border-radius: 18%;
  background: rgba(205, 225, 210, .5);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .12);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: calc(var(--cs) * .62);
  color: var(--ink);
}
.cell.filled { background: var(--tile); box-shadow: 0 2px 0 var(--tile-edge); }
.cell.last { background: rgba(255, 224, 130, .85); box-shadow: 0 0 0 3px #ffc531, 0 0 10px rgba(255, 197, 49, .8); }
.cell.last.filled { background: #ffe9a8; }
.cell.pop { animation: pop .35s ease-out; }
@keyframes pop { 0% { transform: scale(.4); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }

#grid.targeting .cell:not(.filled) { cursor: pointer; animation: pulse .9s ease-in-out infinite; background: rgba(255, 224, 130, .75); }
@keyframes pulse { 50% { transform: scale(.88); } }

/* ---------- word preview ---------- */
#preview {
  flex: 0 0 auto; align-self: center;
  min-width: 56px; height: 42px; margin: 4px 0 8px; padding: 0 18px;
  border-radius: 21px; background: var(--accent-dark);
  font-weight: 800; font-size: 22px; letter-spacing: 3px; line-height: 42px; text-align: center;
  opacity: 0; transition: opacity .12s, background .15s;
}
#preview.on { opacity: 1; }
#preview.ok { background: #28a745; }
#preview.bonus { background: #2f7fd1; }
#preview.dup { background: #c98a14; }
#preview.bad { background: #c0392b; animation: shake .35s; }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(7px); } 60% { transform: translateX(-5px); } 80% { transform: translateX(5px); } }

/* ---------- wheel ---------- */
#wheelArea {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.side { display: flex; flex-direction: column; gap: 14px; width: 48px; flex: 0 0 48px; }
.side.right { align-self: center; }

.rbtn {
  position: relative; width: 48px; height: 48px; padding: 0;
  border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .42);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: #fff;
}
.rbtn:active { transform: scale(.92); }
.rbtn.active { background: #e0a800; }
.cost {
  position: absolute; right: -3px; bottom: -3px;
  min-width: 22px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: #ffc531; color: #5a3d00;
  font-size: 11px; font-weight: 800; line-height: 18px; text-align: center;
}

#wheel {
  --wheel: min(calc(100vw - 150px), 300px, 40vh);
  --wheel: min(calc(100vw - 150px), 300px, 40dvh);
  position: relative; flex: 0 0 auto;
  width: var(--wheel); height: var(--wheel);
  touch-action: none;
}
#disc { position: absolute; inset: 0; border-radius: 50%; background: rgba(215, 235, 222, .88); box-shadow: 0 4px 14px rgba(0, 0, 0, .3); }
#lineSvg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; overflow: visible; }
#line { fill: none; stroke: var(--accent); stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
#tiles { position: absolute; inset: 0; z-index: 1; }

.tile {
  position: absolute; transform: translate(-50%, -50%);
  border-radius: 14%;
  background: var(--tile); box-shadow: 0 3px 0 var(--tile-edge), 0 5px 8px rgba(0, 0, 0, .25);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: calc(var(--wheel) * .13); color: var(--ink);
  transition: left .32s ease, top .32s ease, background .08s, color .08s;
  pointer-events: none;
}
.tile.sel { background: var(--accent-dark); color: #fff; box-shadow: 0 3px 0 #0e4a25; }

/* ---------- toast / overlay ---------- */
#toast {
  position: absolute; left: 50%; top: 52px; transform: translate(-50%, -8px);
  padding: 8px 16px; border-radius: 18px; background: rgba(0, 0, 0, .72);
  font-weight: 700; font-size: 14px; white-space: nowrap;
  opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 5;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

#overlay {
  position: absolute; inset: 0; z-index: 10;
  display: none; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55);
}
#overlay.show { display: flex; }
.card {
  width: min(86%, 340px); padding: 26px 22px; border-radius: 22px; text-align: center;
  background: var(--tile); color: var(--ink); box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: pop .4s ease-out;
}
.card h2 { margin: 0 0 8px; font-size: 28px; }
.card p { margin: 0 0 20px; font-size: 16px; font-weight: 600; }
.bigbtn {
  border: 0; border-radius: 26px; padding: 14px 34px;
  background: var(--accent); color: #fff; font-size: 18px; font-weight: 800;
  box-shadow: 0 4px 0 var(--accent-dark); cursor: pointer;
}
.bigbtn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--accent-dark); }

/* very short screens (landscape phones) */
@media (max-height: 520px) {
  #wheel { --wheel: min(calc(100vw - 150px), 300px, 46vh); }
  .pill { height: 32px; }
}
