/* Hivebound — modern 3D-feel design (CSS only, no libraries).
   Deep honey/amber scene, glass panels, raised board tray, glossy queen tokens. */
:root {
  --ink: #2e1c05;
  --cream: #fff6df;
  --cream-dim: rgba(255, 246, 223, .82);
  --honey: #f6b73c;
  --honey-hi: #ffd970;
  --honey-lo: #c77400;
  --honey-dark: #8a5200;
  --glass: rgba(56, 32, 4, .66);
  --glass-edge: rgba(246, 183, 60, .38);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--cream);
  font-family: 'Arial Rounded MT Bold', 'Helvetica Rounded', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background:
    radial-gradient(1100px 520px at 85% -8%, rgba(255, 183, 49, .34), transparent 60%),
    radial-gradient(900px 480px at -10% 22%, rgba(255, 122, 26, .20), transparent 55%),
    radial-gradient(700px 700px at 50% 115%, rgba(124, 77, 255, .12), transparent 60%),
    linear-gradient(168deg, #3a2004 0%, #59300a 34%, #2a1602 68%, #180b01 100%);
  background-attachment: fixed;
}
/* soft floating glow orbs behind everything */
body::before {
  content: ''; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(140px 140px at 12% 18%, rgba(255, 214, 90, .20), transparent 70%),
    radial-gradient(190px 190px at 88% 62%, rgba(255, 170, 40, .14), transparent 70%),
    radial-gradient(90px 90px at 70% 12%, rgba(255, 236, 170, .16), transparent 70%);
}

/* ---------------- Hero ---------------- */
.hero { text-align: center; padding: 34px 16px 10px; }
.hero .bee { font-size: 54px; display: inline-block; filter: drop-shadow(0 10px 14px rgba(0,0,0,.45)); animation: beeFloat 3.2s ease-in-out infinite; }
@keyframes beeFloat { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-9px) rotate(5deg); } }
.hero h1 {
  font-size: clamp(46px, 13vw, 68px); margin: 2px 0 0; font-weight: 900; letter-spacing: 1.5px; line-height: 1.02;
  background: linear-gradient(180deg, #fff3c4 8%, #ffd94d 42%, #f39c12 78%, #d97b06);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; color: transparent;
  filter: drop-shadow(0 3px 0 rgba(90, 48, 0, .85)) drop-shadow(0 14px 22px rgba(0,0,0,.45));
}
.tagline { font-size: clamp(16px, 4.6vw, 20px); margin: 8px 0 18px; color: var(--cream-dim); font-weight: 700; letter-spacing: .4px; text-shadow: 0 2px 8px rgba(0,0,0,.5); }

/* Hero visual: perspective mini-board built from real region classes + a floating queen */
.hero-visual { perspective: 700px; width: min(218px, 58vw); margin: 2px auto 20px; position: relative; }
.mini-board {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; border-radius: 14px; overflow: hidden;
  transform: rotateX(16deg) rotateY(-13deg) rotateZ(3deg); transform-style: preserve-3d;
  border: 3px solid rgba(24, 12, 0, .9);
  box-shadow: -18px 26px 38px rgba(0,0,0,.55), 0 6px 0 rgba(24,12,0,.55), inset 0 0 0 2px rgba(255,255,255,.08);
  animation: heroTilt 6s ease-in-out infinite;
}
@keyframes heroTilt { 0%,100% { transform: rotateX(16deg) rotateY(-13deg) rotateZ(3deg) translateY(0); } 50% { transform: rotateX(13deg) rotateY(-9deg) rotateZ(2deg) translateY(-6px); } }
.mini { aspect-ratio: 1; position: relative; display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 2px 3px rgba(255,255,255,.35), inset 0 -3px 5px rgba(0,0,0,.14); }
.mini::after { content: ''; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(155deg, rgba(255,255,255,.40), rgba(255,255,255,.04) 42%, rgba(0,0,0,.07) 88%); }
.hero-token {
  position: absolute; right: -16px; top: -18px; z-index: 2;
  width: 62px; height: 62px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 30px; line-height: 1;
  background: radial-gradient(circle at 32% 26%, #fffbe8 0%, #ffe066 34%, #f6b73c 62%, #e8890c 88%, #c77400 100%);
  box-shadow: 0 14px 20px rgba(0,0,0,.5), 0 4px 6px rgba(0,0,0,.4),
    inset 0 3px 4px rgba(255,255,255,.95), inset 0 -7px 9px rgba(146,64,0,.55), inset 0 0 0 2px rgba(146,64,0,.35);
  animation: beeFloat 3.8s ease-in-out infinite;
}
.mini .mq {
  width: 82%; aspect-ratio: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; position: relative; z-index: 2;
  background: radial-gradient(circle at 32% 26%, #fffbe8 0%, #ffe066 34%, #f6b73c 62%, #e8890c 88%, #c77400 100%);
  box-shadow: 0 3px 5px rgba(30,14,0,.5), inset 0 2px 2px rgba(255,255,255,.95), inset 0 -3px 4px rgba(146,64,0,.55), inset 0 0 0 1.5px rgba(146,64,0,.35);
}

.howto { max-width: 470px; margin: 0 auto 20px; text-align: left; padding: 12px 20px;
  background: var(--glass); border: 1px solid var(--glass-edge); border-radius: 20px;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 18px 36px rgba(0,0,0,.42), inset 0 1px 0 rgba(255,255,255,.16); }
.howto p { margin: 8px 0; color: var(--cream); font-size: 15.5px; text-shadow: 0 1px 4px rgba(0,0,0,.45); }
.fair { font-size: 13px; color: var(--cream-dim); max-width: 490px; margin: 16px auto 0; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.hero-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------------- Buttons: chunky 3D ---------------- */
button {
  font: inherit; font-weight: 800; cursor: pointer; color: var(--ink);
  background: linear-gradient(180deg, #fff8e2, #ffeec0);
  border: 1px solid rgba(146, 90, 0, .55); border-radius: 14px; padding: 9px 16px;
  box-shadow: 0 5px 0 #b57e14, 0 10px 18px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.9);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s ease;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
button:hover { filter: brightness(1.05); }
button:active { transform: translateY(4px); box-shadow: 0 1px 0 #b57e14, 0 4px 10px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.9); }
button.big {
  font-size: 20px; padding: 14px 30px; border-radius: 18px; letter-spacing: .3px;
  background: linear-gradient(180deg, var(--honey-hi) 0%, var(--honey) 52%, #ee9f0a 100%);
  border-color: rgba(120, 64, 0, .6);
  box-shadow: 0 7px 0 var(--honey-lo), 0 16px 28px rgba(0,0,0,.5), inset 0 2px 0 rgba(255,255,255,.75), inset 0 -3px 6px rgba(146,64,0,.35);
  text-shadow: 0 1px 0 rgba(255,244,200,.7);
}
button.big:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--honey-lo), 0 8px 16px rgba(0,0,0,.45), inset 0 2px 0 rgba(255,255,255,.75); }
button.big.alt { background: linear-gradient(180deg, #ffffff, #ffeec4); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

/* ---------------- Panels: glassmorphism ---------------- */
main { max-width: 560px; margin: 0 auto; padding: 10px 12px 34px; }
.panel {
  background: var(--glass); border: 1px solid var(--glass-edge); border-radius: 24px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  padding: 18px 16px; margin-bottom: 16px;
  box-shadow: 0 24px 48px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.16), inset 0 -1px 0 rgba(0,0,0,.35);
}
.hidden { display: none !important; }
.statusbar { display: flex; justify-content: space-between; gap: 8px; font-weight: 800; margin-bottom: 14px;
  color: var(--cream); font-size: 15px; text-shadow: 0 2px 6px rgba(0,0,0,.55); }
body.zen #timer { visibility: hidden; }

/* ---------------- Board: raised tray ---------------- */
#board {
  display: grid; gap: 0; width: 100%; max-width: 480px; margin: 0 auto;
  border-radius: 18px; overflow: hidden; touch-action: manipulation;
  border: 3px solid rgba(20, 10, 0, .95);
  box-shadow:
    inset 0 0 0 5px rgba(46, 24, 2, .92),
    inset 0 0 22px rgba(0,0,0,.45),
    0 26px 44px rgba(0,0,0,.55),
    0 6px 0 rgba(20, 10, 0, .65),
    0 10px 18px rgba(0,0,0,.4);
}
#board.won { animation: boardGlow 1.15s ease-in-out 2; }
@keyframes boardGlow {
  0%, 100% { box-shadow: inset 0 0 0 5px rgba(46,24,2,.92), inset 0 0 22px rgba(0,0,0,.45), 0 26px 44px rgba(0,0,0,.55), 0 6px 0 rgba(20,10,0,.65), 0 10px 18px rgba(0,0,0,.4); }
  50% { box-shadow: inset 0 0 0 5px rgba(46,24,2,.92), inset 0 0 26px rgba(255,190,40,.35), 0 26px 44px rgba(0,0,0,.55), 0 6px 0 rgba(20,10,0,.65), 0 0 42px rgba(255,190,40,.75); }
}
.cell {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center; position: relative;
  font-size: clamp(16px, 6vw, 28px); cursor: pointer; user-select: none; -webkit-user-select: none;
  border-right: 1px solid rgba(46,24,2,.35); border-bottom: 1px solid rgba(46,24,2,.35);
  box-shadow: inset 0 2px 3px rgba(255,255,255,.38), inset 0 -4px 6px rgba(60,30,0,.16), inset 2px 0 3px rgba(255,255,255,.10);
  transition: transform .09s ease, filter .12s ease;
  -webkit-tap-highlight-color: transparent;
}
/* glossy highlight swept over every cell (patterns stay underneath, tokens get a shine too) */
.cell::after { content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 3;
  background: linear-gradient(155deg, rgba(255,255,255,.34), rgba(255,255,255,.05) 42%, rgba(0,0,0,.05) 88%); }
.cell:active { transform: scale(.93); filter: brightness(1.07); z-index: 1; }
.cell.bt { border-top: 3px solid rgba(30,16,0,.92); }
.cell.bb { border-bottom: 3px solid rgba(30,16,0,.92); }
.cell.bl { border-left: 3px solid rgba(30,16,0,.92); }
.cell.br { border-right: 3px solid rgba(30,16,0,.92); }
.cell .x { color: rgba(46,24,2,.52); font-weight: 900; font-size: .82em; text-shadow: 0 1px 0 rgba(255,255,255,.45); transform: rotate(-6deg); display: inline-block; }
/* Queen = physical glossy token */
.cell .queen {
  width: 80%; aspect-ratio: 1; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: .86em; line-height: 1; position: relative; z-index: 2;
  background: radial-gradient(circle at 32% 26%, #fffbe8 0%, #ffe066 34%, #f6b73c 62%, #e8890c 88%, #c77400 100%);
  box-shadow: 0 5px 9px rgba(30,14,0,.5), 0 2px 3px rgba(30,14,0,.4),
    inset 0 2px 3px rgba(255,255,255,.95), inset 0 -5px 7px rgba(146,64,0,.55), inset 0 0 0 2px rgba(146,64,0,.35);
  text-shadow: 0 1px 1px rgba(255,246,200,.8);
}
.cell.just-placed .queen { animation: queenPop .38s cubic-bezier(.2, 2.1, .45, 1); }
@keyframes queenPop { 0% { transform: scale(.25) rotate(-14deg); } 62% { transform: scale(1.16) rotate(4deg); } 100% { transform: scale(1) rotate(0); } }
.cell.conflict { box-shadow: inset 0 0 0 3px #ff5252, inset 0 0 18px rgba(224,49,49,.5); background-color: rgba(224,49,49,.20) !important; }
.cell.hint-flash { animation: pulse 0.9s ease-in-out 3; z-index: 2; }
@keyframes pulse { 50% { box-shadow: inset 0 0 0 4px #37d67a, inset 0 0 16px rgba(55,214,122,.55); } }

/* Region colours — rich bases; gloss overlay above adds the gradient depth.
   Every region also carries a subtle pattern (below) so regions differ by
   texture + tone, not colour alone (colourblind safety). */
.r0 { background-color: #ffd43b; } .r1 { background-color: #ff9d9d; }
.r2 { background-color: #8ec9ff; } .r3 { background-color: #9be89f; }
.r4 { background-color: #c9b3ff; } .r5 { background-color: #ffb877; }
.r6 { background-color: #f7e463; } .r7 { background-color: #7fe3da; }
.r8 { background-color: #f28ec2; } .r9 { background-color: #b9c4cf; }
.p0 { background-image: repeating-linear-gradient(0deg, rgba(58,32,0,.07) 0 2px, transparent 2px 9px); }
.p1 { background-image: radial-gradient(rgba(58,32,0,.17) 1.2px, transparent 1.3px); background-size: 9px 9px; }
.p2 { background-image: radial-gradient(rgba(255,255,255,.30) 1.3px, transparent 1.4px); background-size: 11px 11px; background-position: 3px 3px; }
.p3 { background-image: repeating-linear-gradient(45deg, rgba(58,32,0,.10) 0 2px, transparent 2px 8px); }
.p4 { background-image: radial-gradient(rgba(58,32,0,.13) 1.7px, transparent 1.8px); background-size: 14px 14px; background-position: 5px 2px; }
.p5 { background-image: repeating-linear-gradient(-45deg, rgba(58,32,0,.10) 0 2px, transparent 2px 8px); }
.p6 { background-image: repeating-linear-gradient(90deg, rgba(255,255,255,.20) 0 2px, transparent 2px 10px); }
.p7 { background-image: radial-gradient(rgba(58,32,0,.15) 1.6px, transparent 1.7px); background-size: 13px 13px; }
.p8 { background-image: repeating-linear-gradient(0deg, rgba(255,255,255,.18) 0 2px, transparent 2px 8px); }
.p9 { background-image: repeating-linear-gradient(90deg, rgba(58,32,0,.10) 0 2px, transparent 2px 9px); }

.message { min-height: 42px; text-align: center; color: var(--cream); font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.5); }
.tools, .actions { display: flex; flex-wrap: wrap; gap: 9px; justify-content: center; margin: 10px 0; }
.tool.active { background: linear-gradient(180deg, var(--honey-hi), var(--honey) 55%, #ee9f0a); box-shadow: 0 5px 0 var(--honey-lo), 0 10px 18px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.8); }
.toggles { display: flex; flex-direction: column; gap: 7px; align-items: center; font-size: 14px; color: var(--cream-dim); font-weight: 600; }
.toggles input { accent-color: var(--honey); width: 17px; height: 17px; vertical-align: -3px; }

/* Win panel celebration */
#winPanel { position: relative; overflow: hidden; text-align: center; animation: winIn .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes winIn { from { transform: scale(.9) translateY(14px); opacity: 0; } to { transform: scale(1) translateY(0); opacity: 1; } }
#winPanel h2 { margin: 4px 0 6px; font-size: 27px; color: var(--honey-hi); text-shadow: 0 2px 0 rgba(90,48,0,.8), 0 8px 18px rgba(0,0,0,.5); }
#winText { color: var(--cream); font-weight: 700; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 13px; border-radius: 2px; opacity: 0; animation: confettiFall 1.7s ease-in forwards; }
@keyframes confettiFall {
  0% { opacity: 1; transform: translate(0, 0) rotate(0deg); }
  100% { opacity: 0; transform: translate(var(--drift, 0px), 300px) rotate(560deg); }
}
#shareText { width: 100%; font-family: ui-monospace, monospace; font-size: 13px; border-radius: 12px; padding: 10px;
  background: rgba(20, 10, 0, .55); color: var(--cream); border: 1px solid var(--glass-edge); }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(16, 7, 0, .62); backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal-card { background: linear-gradient(170deg, rgba(84, 46, 6, .94), rgba(44, 23, 2, .96)); border: 1px solid var(--glass-edge);
  border-radius: 22px; padding: 22px; max-width: 520px; width: 92%; max-height: 86vh; overflow: auto; text-align: center;
  color: var(--cream); box-shadow: 0 30px 60px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.18); }
.modal-card h2 { color: var(--honey-hi); margin-top: 2px; text-shadow: 0 2px 6px rgba(0,0,0,.5); }
#levelsGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 7px; margin: 12px 0; }
#levelsGrid button.done { background: linear-gradient(180deg, #d3f9d8, #8ce99a); box-shadow: 0 5px 0 #4c9a57, 0 10px 18px rgba(0,0,0,.35); }
.store-item { border: 2px dashed rgba(246,183,60,.65); border-radius: 16px; padding: 14px; margin: 12px 0; background: rgba(255, 214, 90, .07); }
.note { font-size: 13px; color: var(--cream-dim); }
footer { text-align: center; font-size: 12px; color: rgba(255,246,223,.6); padding: 14px; }

/* Small phones: keep the hero board and headline in proportion */
@media (max-width: 380px) {
  .hero { padding-top: 24px; }
  .hero-visual { width: 176px; }
  button.big { padding: 13px 22px; font-size: 18px; }
  .panel { padding: 14px 11px; border-radius: 20px; }
}
/* Respect users who prefer calm motion */
@media (prefers-reduced-motion: reduce) {
  .hero .bee, .mini-board, .hero-token, .cell.just-placed .queen, #winPanel, #board.won { animation: none !important; }
  .confetti i { display: none; }
}
