:root {
  color-scheme: light;
  --felt: #14532d;
  --felt-dark: #0c3a20;
  --tile: #faf7ef;
  --tile-edge: #d8d2c2;
  --ink: #1c1917;
  --accent: #f59e0b;
  --good: #16a34a;
  --bad: #dc2626;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--felt-dark);
  color: #f5f5f4;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 8px;
}

.title { font-weight: 800; font-size: 20px; }
.title small { font-weight: 500; font-size: 12px; color: #d6d3d1; }
.spacer { flex: 1; }
.hud { font-size: 15px; background: rgba(0,0,0,.25); border-radius: 999px; padding: 4px 12px; }
.hud .sep { color: #a8a29e; margin: 0 4px; }

#status {
  font-size: 14px;
  color: #fef3c7;
  min-height: 20px;
  margin: 0 2px 6px;
}

#board-wrap {
  background: var(--felt);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 12px;
  padding: 10px 6px;
  min-height: 118px;
}

#board {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  justify-content: center;
  max-height: 220px;
  overflow-y: auto;
}

.board-empty { color: #d6d3d1; font-size: 13px; }

#midbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 2px;
}

.ends { display: flex; gap: 6px; }
.end {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.25);
  color: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  font-size: 15px;
  cursor: pointer;
}
.end.active { background: var(--accent); border-color: var(--accent); color: #1c1917; font-weight: 800; }

.pile { font-size: 13px; color: #d6d3d1; flex: 1; text-align: right; }

.btn {
  border: 1px solid rgba(255,255,255,.35);
  background: rgba(0,0,0,.25);
  color: #fff;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1c1917; }
.btn:disabled { opacity: .4; cursor: default; }

#hand {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  padding: 4px 0 2px;
  min-height: 76px;
}

.tile {
  background: var(--tile);
  border: 1px solid var(--tile-edge);
  border-radius: 8px;
  padding: 4px;
  display: flex;
  gap: 4px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,.4);
}
.board .tile { cursor: default; }
.tile.vertical { flex-direction: column; }
.tile.playable { outline: 3px solid var(--good); }
.tile.chosen { outline: 3px solid var(--accent); transform: translateY(-3px); }
.tile.fresh { animation: pop .25s ease-out; }
@keyframes pop {
  0% { transform: scale(.7); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

.half {
  width: 26px;
  height: 26px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 1px;
  padding: 2px;
  background: #fff;
  border-radius: 4px;
}
.tile + .tile { margin-left: 0; }
.half + .half { border-left: 2px solid var(--ink); }
.tile.vertical .half + .half { border-left: none; border-top: 2px solid var(--ink); }

.pip { border-radius: 50%; }
.pip.on { background: var(--ink); }

#statusbar { margin-top: 8px; }
#statusbar .actions { display: flex; gap: 8px; justify-content: center; }

#how {
  margin-top: 8px;
  font-size: 13px;
  line-height: 1.5;
  background: rgba(0,0,0,.3);
  border-radius: 10px;
  padding: 8px 12px;
}
#how.hidden { display: none; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  color: #fff;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  max-width: 92vw;
  text-align: center;
}
#toast.show { opacity: 1; }

html.touch .tile { padding: 6px; }
html.touch .half { width: 30px; height: 30px; }
html.touch .btn, html.touch .end { padding-top: 9px; padding-bottom: 9px; }
