:root {
  --navy: #102457;
  --cream: #fff8e8;
  --paper: #fffdf7;
  --teal: #078a91;
  --teal-dark: #05666c;
  --yellow: #ffc928;
  --coral: #f06451;
  --purple: #7542b9;
  --line: #e7d6ad;
  --shadow: 0 14px 40px rgba(26, 46, 77, .18);
  --font: "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--navy); background: radial-gradient(circle at 10% 10%, #fffdf3, #f7e9c4); font-family: var(--font); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 5px solid #32b8ff; outline-offset: 3px; }
[hidden] { display: none !important; }

.setup-screen { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, .9fr) minmax(520px, 1.1fr); overflow: hidden; }
.setup-art { display: grid; place-items: end center; position: relative; background: url("assets/adventure-map-v2.png") center/cover; }
.setup-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(90deg, rgba(255,255,255,.05), var(--cream)); }
.setup-art img { position: relative; z-index: 1; width: min(72%, 540px); max-height: 88vh; object-fit: contain; filter: drop-shadow(0 24px 18px rgba(20,51,66,.25)); animation: float 3.2s ease-in-out infinite; }
.setup-panel { background: var(--cream); padding: clamp(28px, 5vw, 76px); display: flex; flex-direction: column; justify-content: center; gap: 18px; }
.brand { display: flex; gap: 18px; align-items: flex-start; }
.brand > span { font-size: 56px; filter: drop-shadow(0 5px 0 #d99e00); }
h1, h2, p { margin-top: 0; }
.brand h1 { margin-bottom: 8px; font-size: clamp(40px, 5vw, 68px); line-height: .96; letter-spacing: -2px; }
.brand p { font-size: 20px; }
.teacher-note { display: flex; gap: 14px; padding: 14px 18px; border: 2px solid #a9ddd8; border-radius: 18px; background: #e9fbf8; }
.teacher-note strong { color: var(--teal-dark); white-space: nowrap; }
.setup-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.setup-grid label, .team-name-fields label { display: grid; gap: 7px; font-size: 14px; font-weight: 900; }
select, input { min-height: 48px; border: 2px solid var(--line); border-radius: 13px; padding: 9px 12px; color: var(--navy); background: white; }
.team-name-fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; max-height: 230px; overflow: auto; padding: 3px; }
.privacy { margin: 0; text-align: center; font-size: 13px; opacity: .72; }

.primary, .secondary, .quiet, .danger-button { border: 0; border-radius: 15px; min-height: 48px; padding: 11px 18px; font-weight: 900; color: var(--navy); }
.primary { color: white; background: linear-gradient(#0dafaf, #087e85); box-shadow: 0 6px 0 #055f66; }
.secondary { color: var(--navy); background: #fff; border: 2px solid var(--line); box-shadow: 0 4px 0 #ddc58b; }
.giant { min-height: 62px; font-size: 21px; }
.danger-button { color: white; background: #c84236; }

.game-shell { min-height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #e8f5f4; }
.topbar { min-height: 82px; display: grid; grid-template-columns: minmax(250px, 1fr) minmax(260px, .9fr) auto auto auto; align-items: center; gap: 18px; padding: 12px 22px; background: var(--paper); border-bottom: 3px solid #d8c18b; box-shadow: 0 4px 14px rgba(16,36,87,.12); z-index: 5; }
.compact-brand { display: flex; align-items: center; gap: 12px; font-size: clamp(18px, 2vw, 26px); }
.compact-brand span { font-size: 38px; }
.energy > div:first-child { display: flex; justify-content: space-between; margin-bottom: 5px; }
.energy-track { height: 17px; padding: 3px; border: 2px solid #d4a72e; border-radius: 20px; background: #fff4c9; }
.energy-track i { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #65ba37, #09a667); transition: width .5s; }
.clock { font-size: 24px; padding: 10px 14px; border: 2px solid #edd39a; border-radius: 16px; background: white; }
.quiet { background: #edf5f5; border: 2px solid #bcd3d2; }
.quiet.danger { color: #a63229; background: #fff0ed; border-color: #f4b8ae; }

.game-main { display: grid; min-height: 0; grid-template-columns: minmax(0, 1.3fr) minmax(520px, 1fr); padding: 16px; gap: 16px; }
.map-panel { position: relative; overflow: hidden; min-height: 520px; border: 5px solid white; border-radius: 30px; background: #7bd1ef; box-shadow: var(--shadow); }
.map-art { width: 100%; height: 100%; object-fit: cover; display: block; }
.map-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(16,36,87,.16), transparent 28%, transparent 75%, rgba(16,36,87,.18)); pointer-events: none; }
.route-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; filter: drop-shadow(0 4px 4px rgba(16,36,87,.34)); }
.route-overlay polyline { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.route-shadow { stroke: rgba(74,63,28,.45); stroke-width: 13; }
.route-line { stroke: #ffd447; stroke-width: 9; stroke-dasharray: 2 18; }
.map-heading { position: absolute; top: 18px; left: 20px; display: flex; gap: 12px; align-items: center; padding: 10px 15px; border: 3px solid white; border-radius: 18px; background: rgba(255,253,247,.94); box-shadow: 0 7px 18px rgba(16,36,87,.18); }
.map-heading span { padding: 7px 11px; border-radius: 11px; color: white; background: var(--purple); }
.route-spaces { position: absolute; inset: 0; pointer-events: none; }
.route-space { position: absolute; left: var(--x); top: var(--y); width: 12px; height: 12px; transform: translate(-50%, -50%); border: 2px solid white; border-radius: 50%; background: var(--station); box-shadow: 0 2px 4px rgba(16,36,87,.35); }
.team-markers { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.map-marker { position: absolute; left: var(--x); top: var(--y); z-index: 4; display: grid; place-items: center; width: 50px; height: 58px; transform: translate(-50%, -100%); border: 4px solid white; border-radius: 50% 50% 50% 8px; background: var(--team); box-shadow: 0 7px 0 rgba(16,36,87,.26), 0 10px 18px rgba(16,36,87,.28); font-size: 25px; transition: left .6s, top .6s; }
.map-marker em { position: absolute; right: -13px; top: -12px; display: grid; place-items: center; min-width: 29px; height: 29px; padding: 2px; border: 3px solid white; border-radius: 50%; color: white; background: var(--navy); box-shadow: 0 3px 6px rgba(16,36,87,.3); font-size: 12px; font-style: normal; font-weight: 900; }
.map-marker.is-active { z-index: 2; animation: markerBounce 1s infinite; }

.task-card { display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding: 20px; border: 5px solid #8351c5; border-radius: 30px; background: var(--paper); box-shadow: var(--shadow), inset 0 0 0 4px #f1d9ff; }
.round-panel { gap: 12px; }
.round-intro { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.task-header { display: flex; gap: 12px; align-items: center; padding-bottom: 13px; border-bottom: 3px dashed #d9c4ec; }
.task-header > span { display: grid; place-items: center; width: 58px; height: 58px; flex: none; border-radius: 18px; background: #f3e9ff; font-size: 32px; }
.task-header small { text-transform: uppercase; color: var(--purple); font-weight: 900; letter-spacing: .7px; }
.task-header h2 { margin: 2px 0 0; font-size: clamp(24px, 2.1vw, 34px); }
.pati-row { min-height: 0; flex: 1; display: grid; grid-template-columns: 30% 1fr; align-items: center; gap: 8px; }
.pati-row img { width: 140%; max-height: 280px; object-fit: contain; transform: translateX(-12%); filter: drop-shadow(0 10px 10px rgba(16,36,87,.16)); }
.speech { position: relative; align-self: stretch; display: flex; flex-direction: column; justify-content: center; padding: 17px; margin: 16px 0; border: 3px solid #f0cd65; border-radius: 20px; background: #fff9df; }
.speech::before { content: ""; position: absolute; left: -15px; top: 42%; width: 24px; height: 24px; transform: rotate(45deg); border-left: 3px solid #f0cd65; border-bottom: 3px solid #f0cd65; background: #fff9df; }
.speech p { position: relative; margin: 0; font-size: clamp(18px, 1.65vw, 25px); line-height: 1.35; }
.speech .hint { margin-top: 13px; padding: 11px; border-radius: 12px; color: #4f3781; background: #f1e7ff; font-size: 15px; }
.task-actions { text-align: center; }
.dice-button { width: 100%; min-height: 88px; border: 0; border-radius: 22px; color: white; background: linear-gradient(145deg, #8650cb, #59329e); box-shadow: 0 8px 0 #3c2673; }
.dice-button span, .dice-button b, .dice-button small { display: block; }
.dice-button .dice { font-size: 34px; }
.dice-button b { font-size: 22px; }
.dice-button small { opacity: .8; }
.dice-button:disabled { opacity: .55; box-shadow: none; cursor: wait; }
.dice-turn-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin: 0 0 12px; padding: 0; list-style: none; }
.dice-turn-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 7px; align-items: center; padding: 8px 10px; border: 2px solid color-mix(in srgb, var(--team), white 45%); border-radius: 12px; background: color-mix(in srgb, var(--team), white 91%); font-size: 12px; }
.dice-turn-list li.is-next { box-shadow: 0 0 0 4px color-mix(in srgb, var(--team), white 55%); animation: nextPulse 1s infinite alternate; }
.dice-turn-list li.is-rolled { color: white; background: var(--team); }
.dice-turn-list li b { white-space: nowrap; }
.task-controls { display: grid; gap: 11px; }
.task-timer { justify-self: center; padding: 8px 16px; border: 2px solid #f0cd65; border-radius: 30px; background: #fff6c8; font-size: 22px; }
.control-grid { display: grid; grid-template-columns: 1fr 1.25fr; gap: 9px; }
.control-grid .primary { grid-column: 1 / -1; min-height: 56px; font-size: 19px; }
.speaker-chip { margin-top: 13px; padding: 10px; text-align: center; border-radius: 13px; background: #eee6f8; }
.task-arrive { animation: taskPop .6s both; }
.round-task-board { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; min-height: 0; overflow: auto; padding: 2px; }
.round-task { display: flex; flex-direction: column; min-height: 245px; padding: 13px; border: 3px solid var(--team); border-radius: 18px; background: color-mix(in srgb, var(--team), white 92%); box-shadow: 0 5px 0 color-mix(in srgb, var(--team), white 45%); }
.round-task.is-done { opacity: .66; filter: saturate(.65); }
.round-task header { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; }
.round-task header > span { font-size: 27px; }
.round-task header strong, .round-task header small { display: block; }
.round-task header small { margin-top: 2px; font-size: 11px; opacity: .75; }
.roll-badge { display: grid; place-items: center; min-width: 62px; min-height: 52px; padding: 5px; color: white; border: 3px solid white; border-radius: 15px; background: var(--team); box-shadow: 0 4px 0 color-mix(in srgb, var(--team), black 20%); font-size: 24px; }
.round-task > p { flex: 1; margin: 12px 0; font-family: var(--font); font-size: clamp(15px, 1.15vw, 18px); line-height: 1.3; }
.round-task details { margin-bottom: 10px; padding: 7px 9px; border-radius: 10px; background: white; font-size: 12px; }
.round-task details summary { cursor: pointer; font-weight: 900; }
.round-task details span { display: block; margin-top: 6px; }
.round-task footer { display: flex; align-items: center; justify-content: space-between; gap: 7px; font-size: 12px; }
.round-task footer button { min-height: 38px; padding: 7px 10px; font-size: 12px; }
.round-task footer button:disabled { color: #425267; background: #dbe8e6; box-shadow: none; cursor: default; }
.round-toolbar { display: grid; grid-template-columns: auto 1fr 1fr; gap: 9px; align-items: center; padding-top: 8px; border-top: 2px dashed #d9c4ec; }
.round-toolbar .task-timer { white-space: nowrap; font-size: 17px; }
.round-toolbar button:disabled { opacity: .45; box-shadow: none; cursor: not-allowed; }
.dice-score-preview { display: inline-block; margin: 5px auto 10px; padding: 9px 16px; border: 3px solid #e0aa1c; border-radius: 15px; background: #fff4bd; font-size: 21px; }

.team-rail { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 10px; padding: 12px 16px 16px; background: var(--paper); border-top: 3px solid #d8c18b; }
.team-card { position: relative; display: grid; grid-template-columns: auto auto 1fr auto; gap: 9px; align-items: center; min-width: 0; padding: 10px 12px; border: 3px solid color-mix(in srgb, var(--team), white 36%); border-radius: 17px; background: color-mix(in srgb, var(--team), white 88%); }
.team-card.is-active { transform: translateY(-4px); box-shadow: 0 7px 0 var(--team); }
.team-card .rank { display: grid; place-items: center; width: 27px; height: 27px; color: white; border-radius: 50%; background: var(--team); }
.team-icon { font-size: 27px; }
.team-card div { min-width: 0; }
.team-card strong, .team-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team-card small { font-size: 11px; opacity: .72; }
.team-score { font-size: 19px; }
.settings { position: fixed; right: 12px; bottom: 11px; z-index: 7; width: 160px; padding: 8px 11px; border: 2px solid #c7d4d4; border-radius: 13px; background: white; box-shadow: var(--shadow); font-size: 12px; }
.settings summary { cursor: pointer; font-weight: 900; }
.settings label, .settings button { display: block; margin-top: 9px; }

.modal { width: min(92vw, 570px); border: 5px solid white; border-radius: 28px; padding: 28px; color: var(--navy); background: var(--paper); box-shadow: 0 25px 80px rgba(9,22,52,.42); text-align: center; }
.modal::backdrop { background: rgba(16,36,87,.66); backdrop-filter: blur(5px); }
.modal-icon { font-size: 55px; }
.modal h2 { margin: 5px 0 8px; font-size: 34px; }
.score-choice { display: block; margin: 10px 0; }
.score-choice input { position: absolute; opacity: 0; }
.score-choice span { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; padding: 14px 16px; border: 3px solid #ded4c2; border-radius: 16px; background: white; text-align: left; transition: transform .15s, border-color .15s, background .15s; }
.score-choice b { font-size: 18px; }
.score-choice small { grid-column: 1; color: #5d6680; line-height: 1.25; }
.score-choice strong { grid-column: 2; grid-row: 1 / span 2; align-self: center; padding: 8px; border-radius: 11px; color: white; background: var(--navy); white-space: nowrap; }
.score-choice input:checked + span { transform: translateX(4px); border-color: var(--teal); background: #ddf7f3; box-shadow: inset 8px 0 var(--teal); }
.score-choice.collaboration input:checked + span { border-color: #15865d; background: #e0f8e8; box-shadow: inset 8px 0 #15865d; }
.score-choice.great input:checked + span { border-color: #d79b00; background: #fff5c9; box-shadow: inset 8px 0 #d79b00; }
.score-choice.partial input:checked + span { border-color: #6c7c96; background: #eef2f7; box-shadow: inset 8px 0 #6c7c96; }
.modal .primary:disabled { opacity: .45; box-shadow: none; cursor: not-allowed; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.celebration { overflow: visible; border-color: #ffe07b; background: radial-gradient(circle, #fffef5, #fff3bc); }
.burst { font-size: 74px; animation: burst 1s infinite alternate; }
.celebration-stars { margin: 18px 0 25px; font-size: 50px; letter-spacing: 8px; filter: drop-shadow(0 6px 0 #e4a900); }

.final-screen { min-height: 100vh; position: relative; display: grid; place-items: center; align-content: center; padding: 30px; text-align: center; overflow: hidden; background: radial-gradient(circle at center, #fffde6 0 25%, #c9f5ef 65%, #7ed9dc); }
.final-screen > img { position: absolute; left: 4vw; bottom: -10vh; width: min(30vw, 390px); filter: drop-shadow(0 20px 20px rgba(16,36,87,.2)); }
.trophy { font-size: 110px; filter: drop-shadow(0 10px 0 #c58c00); }
.final-screen > p:first-of-type { margin: 15px 0 4px; color: #7a4c00; text-transform: uppercase; letter-spacing: 2px; font-weight: 900; }
.final-screen h1 { margin: 0; font-size: clamp(42px, 7vw, 84px); }
.final-copy { max-width: 700px; font-size: 20px; }
.final-ranking { width: min(90vw, 630px); margin: 10px auto 22px; padding: 0; list-style: none; }
.final-ranking li { display: grid; grid-template-columns: 1fr auto; gap: 4px 18px; margin: 7px; padding: 11px 15px; border-left: 12px solid var(--team); border-radius: 13px; background: white; box-shadow: 0 5px 15px rgba(16,36,87,.12); text-align: left; }
.final-ranking li small { grid-column: 1/-1; color: #5f6580; }

#confetti { position: fixed; inset: 0; z-index: 100; pointer-events: none; overflow: hidden; }
#confetti i { position: absolute; left: var(--left); top: -20px; width: 12px; height: 20px; border-radius: 3px; background: var(--color); animation: confetti 2.3s var(--delay) ease-in forwards; }
.dice-result-pop { position: fixed; left: 50%; top: 44%; z-index: 90; min-width: 280px; padding: 20px 30px; transform: translate(-50%, -50%); border: 6px solid white; border-radius: 28px; color: white; background: var(--team); box-shadow: 0 24px 80px rgba(16,36,87,.45); text-align: center; animation: dicePop 1s both; }
.dice-result-pop span, .dice-result-pop small { display: block; }
.dice-result-pop span { font-size: 22px; font-weight: 900; }
.dice-result-pop strong { display: block; margin: 4px; font-size: 88px; line-height: .95; text-shadow: 0 6px 0 rgba(16,36,87,.25); }
.dice-result-pop small { font-size: 18px; font-weight: 900; }

@keyframes float { 50% { transform: translateY(-14px) rotate(1deg); } }
@keyframes markerBounce { 50% { transform: translate(-50%, -115%) scale(1.12); } }
@keyframes taskPop { from { opacity: .4; transform: scale(.96); } 60% { transform: scale(1.02); } }
@keyframes burst { to { transform: scale(1.13) rotate(7deg); } }
@keyframes confetti { to { top: 110vh; transform: rotate(var(--spin)) translateX(80px); } }
@keyframes dicePop { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.4) rotate(-10deg); } 35% { opacity: 1; transform: translate(-50%, -50%) scale(1.12) rotate(3deg); } 100% { transform: translate(-50%, -50%) scale(1); } }
@keyframes nextPulse { to { transform: translateY(-2px); } }

.reduced-motion * {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 1100px) {
  .topbar { grid-template-columns: 1fr auto auto; }
  .energy { grid-row: 2; grid-column: 1 / -1; }
  .game-main { grid-template-columns: 1fr; overflow: auto; }
  .map-panel { min-height: 500px; }
  .task-card { min-height: 540px; }
  .team-rail { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .setup-screen { grid-template-columns: 1fr; }
  .setup-art { min-height: 280px; }
  .setup-art img { max-height: 300px; }
  .setup-panel { padding: 26px 18px; }
  .brand h1 { font-size: 42px; }
  .setup-grid { grid-template-columns: 1fr; }
  .team-name-fields { grid-template-columns: 1fr; }
  .topbar { padding: 8px; gap: 7px; }
  .compact-brand strong { font-size: 15px; }
  .compact-brand span { font-size: 27px; }
  .clock { font-size: 17px; }
  .quiet { padding: 8px; font-size: 12px; }
  .game-main { padding: 8px; }
  .map-panel { min-height: 390px; }
  .pati-row { grid-template-columns: 26% 1fr; }
  .pati-row img { width: 160%; }
  .round-task-board { grid-template-columns: 1fr; }
  .round-toolbar { grid-template-columns: 1fr; }
  .dice-turn-list { grid-template-columns: 1fr; }
  .team-rail { grid-template-columns: 1fr; }
  .settings { position: static; width: auto; margin: 0 8px 8px; }
  .final-screen > img { display: none; }
}
