:root {
  --ink: #182333;
  --muted: #697386;
  --cream: #fff9f0;
  --paper: rgba(255, 255, 255, 0.88);
  --line: #eadfce;
  --blue: #1676b9;
  --blue-dark: #07558d;
  --blue-light: #5cc3ed;
  --red: #e64b45;
  --red-dark: #9e262d;
  --black: #30343b;
  --pink: #ed3b81;
  --orange: #ff8a3c;
  --yellow: #f8c84c;
  --green: #65a746;
  --shadow: 0 18px 50px rgba(45, 41, 35, 0.1);
  font-family: Avenir, "Avenir Next", "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--cream);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 5% 8%, rgba(248, 200, 76, 0.19), transparent 22rem),
    radial-gradient(circle at 90% 80%, rgba(22, 118, 185, 0.13), transparent 28rem),
    linear-gradient(135deg, #fffdf8 0%, #fff7ed 55%, #fffdf7 100%);
}

body.presentation-fullscreen {
  overflow: hidden;
}

body.presentation-fullscreen .app-shell {
  width: 100%;
  max-width: none;
}

button, dialog { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 4px solid rgba(22, 118, 185, 0.28); outline-offset: 3px; }

.app-shell { width: min(1600px, 100%); min-height: 100vh; margin: 0 auto; padding: 22px 30px 18px; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-logo { display: block; width: clamp(176px, 18vw, 235px); height: auto; mix-blend-mode: multiply; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.classroom-chip { padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); background: rgba(255,255,255,.55); font-size: .84rem; font-weight: 700; }
.icon-button { display: inline-flex; align-items: center; gap: 7px; min-height: 42px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 13px; color: var(--ink); background: rgba(255,255,255,.72); font-weight: 750; cursor: pointer; }
.icon-button:hover { background: white; transform: translateY(-1px); }
.icon-button[aria-pressed="false"] { color: #a9a5a0; }
.info-trigger {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  width: 25px;
  height: 25px;
  padding: 0;
  border: 2px solid white;
  border-radius: 50%;
  color: white;
  background: linear-gradient(145deg, var(--blue-light), var(--blue-dark));
  box-shadow: 0 5px 12px rgba(9, 89, 145, .24);
  font-family: Georgia, serif;
  font-size: .86rem;
  font-weight: 900;
  line-height: 1;
  cursor: help;
  transition: transform .16s ease, box-shadow .16s ease, filter .16s ease;
}
.info-trigger:hover,
.info-trigger:focus-visible {
  transform: translateY(-2px) scale(1.06);
  filter: brightness(1.08);
  box-shadow: 0 8px 16px rgba(9, 89, 145, .3);
}
.header-info-trigger { width: 34px; height: 34px; font-size: 1rem; }
.compact-info-trigger { width: 22px; height: 22px; font-size: .75rem; }
.title-with-info { display: inline-flex; align-items: center; gap: 8px; }
.fullscreen-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  justify-content: center;
  color: var(--ink);
}
.fullscreen-button span:first-child { font-size: 1.18rem; line-height: 1; }
.fullscreen-button span:last-child {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.fullscreen-button[aria-pressed="true"] {
  color: white;
  border-color: transparent;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  box-shadow: 0 8px 18px rgba(9, 89, 145, .2);
}
.fullscreen-button:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.game-board { display: grid; grid-template-columns: minmax(300px, .95fr) minmax(430px, 1.3fr) minmax(300px, .9fr); gap: 18px; align-items: stretch; }
.panel { min-width: 0; min-height: 670px; padding: clamp(22px, 2.5vw, 38px); border: 1px solid rgba(231, 220, 202, .92); border-radius: 34px; background: var(--paper); box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.panel h1 { margin: 4px 0 0; font-size: clamp(1.65rem, 2.4vw, 2.35rem); line-height: 1.08; }
.eyebrow { color: var(--pink); font-size: .72rem; font-weight: 900; letter-spacing: .17em; text-transform: uppercase; }
.panel-intro { max-width: 28rem; margin: 12px 0 24px; color: var(--muted); line-height: 1.5; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.cards-panel { position: relative; overflow: hidden; display: flex; flex-direction: column; }
.cards-panel::before, .cards-panel::after { content: ""; position: absolute; width: 180px; height: 180px; border: 28px solid rgba(248, 200, 76, .09); transform: rotate(45deg); pointer-events: none; }
.cards-panel::before { left: -130px; top: 170px; }
.cards-panel::after { right: -130px; bottom: -80px; border-color: rgba(237, 59, 129, .07); }
.game-box-figure {
  position: relative;
  z-index: 2;
  width: 96px;
  margin: 6px auto 0;
  text-align: center;
}
.game-box-figure img {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 8px 10px rgba(24, 35, 51, .14));
}
.game-box-figure figcaption {
  margin-top: -3px;
  color: var(--muted);
  font-size: .58rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.deck-counter { display: flex; align-items: center; gap: 10px; min-width: 72px; padding: 9px 12px; border-radius: 14px; background: #fff5f8; color: var(--pink); }
.mini-deck { position: relative; width: 22px; height: 28px; border: 2px solid var(--pink); border-radius: 4px; background: white; box-shadow: -4px 4px 0 rgba(237,59,129,.18); }
.cards-stage { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(5, minmax(46px, 1fr)); align-items: center; gap: 8px; min-height: 285px; margin: auto 0; padding: 18px 0 24px; perspective: 800px; }
.number-card { position: relative; isolation: isolate; display: grid; place-items: center; width: 100%; aspect-ratio: 2 / 3.05; overflow: hidden; border: 4px solid var(--pink); border-radius: 12px; background: #fffefb; box-shadow: 0 11px 20px rgba(91, 37, 58, .15); transform: translateY(var(--lift, 0)) rotate(var(--tilt, 0deg)); transition: transform .25s ease; }
.number-card:hover { z-index: 4; transform: translateY(calc(var(--lift, 0) - 10px)) rotate(0deg) scale(1.06); }
.number-card::before, .number-card::after { content: "◆  +  ●  ✦  ■"; position: absolute; left: -4px; right: -4px; z-index: -1; height: 27px; overflow: hidden; color: var(--yellow); font-size: 10px; line-height: 24px; letter-spacing: 2px; text-align: center; background: repeating-linear-gradient(90deg, #fff 0 8px, #e8f3e1 8px 16px); border-bottom: 2px solid rgba(237,59,129,.12); }
.number-card::before { top: 0; }
.number-card::after { bottom: 0; transform: rotate(180deg); }
.card-corner { position: absolute; z-index: 2; color: var(--pink); font-size: clamp(.55rem, .8vw, .72rem); font-weight: 900; }
.card-corner.top { top: 27px; left: 5px; }
.card-corner.bottom { right: 5px; bottom: 27px; transform: rotate(180deg); }
.card-number { font-size: clamp(1.8rem, 3.4vw, 4rem); font-weight: 950; line-height: 1; letter-spacing: -.07em; background: linear-gradient(90deg, #f04c4f 0 25%, #eaa719 25% 45%, #4a9a43 45% 65%, #1478b9 65% 86%, #e73985 86%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.number-card.dealing { animation: deal-card .58s cubic-bezier(.2,.85,.25,1.2) backwards; animation-delay: var(--delay); }
@keyframes deal-card { from { opacity: 0; transform: translate(-80px, 50px) rotate(-18deg) scale(.74); } }
.card-actions { position: relative; z-index: 2; display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.helper-text { position: relative; z-index: 2; min-height: 2.3em; margin: 14px 0 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }

.primary-button, .secondary-button, .text-button { border: 0; cursor: pointer; font-weight: 850; transition: transform .16s ease, box-shadow .16s ease, filter .16s ease; }
.primary-button { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 52px; padding: 13px 20px; border-radius: 16px; color: white; background: linear-gradient(135deg, var(--blue), var(--blue-dark)); box-shadow: 0 10px 22px rgba(9, 89, 145, .25); }
.primary-button.coral { background: linear-gradient(135deg, #f56a53, #e83c6d); box-shadow: 0 10px 22px rgba(232, 60, 109, .23); }
.primary-button:hover, .secondary-button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.primary-button:active, .secondary-button:active { transform: translateY(1px); }
.primary-button:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }
.text-button { padding: 10px 8px; color: var(--muted); background: transparent; }
.text-button:hover { color: var(--pink); }
.deck-mode-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid rgba(237, 59, 129, .18);
  border-radius: 999px;
  color: var(--muted);
  background: #fff7fa;
  font-size: .74rem;
  font-weight: 850;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, color .16s ease, background .16s ease;
}
.deck-mode-button:hover { transform: translateY(-1px); color: var(--pink); background: #fff; }
.deck-mode-button[aria-pressed="true"] {
  color: white;
  background: linear-gradient(135deg, #ed3b81, #f56a53);
  box-shadow: 0 8px 18px rgba(237, 59, 129, .2);
}
.deck-mode-wrap { display: inline-flex; align-items: center; justify-content: flex-end; gap: 6px; }

.dice-panel { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; background: linear-gradient(150deg, rgba(255,255,255,.96), rgba(238,248,252,.93)); }
.dice-panel::before { content: ""; position: absolute; inset: auto -120px -170px auto; width: 420px; height: 420px; border-radius: 50%; background: radial-gradient(circle, rgba(80,184,224,.2), transparent 66%); pointer-events: none; }
.dice-heading { text-align: center; }
.dice-heading p { margin: 8px 0 12px; color: var(--muted); font-size: .86rem; }
.difficulty-switch, .time-switch { display: flex; gap: 6px; padding: 5px; border: 1px solid var(--line); border-radius: 15px; background: rgba(255,255,255,.78); }
.difficulty-option, .time-option { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 37px; padding: 8px 11px; border: 0; border-radius: 11px; color: var(--muted); background: transparent; font-size: .76rem; font-weight: 850; cursor: pointer; }
.difficulty-option.selected, .time-option.selected { color: var(--ink); background: white; box-shadow: 0 5px 14px rgba(38, 46, 54, .1); }
.difficulty-option:disabled { opacity: .62; cursor: wait; }
.color-dot { width: 10px; height: 10px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(255,255,255,.24); }
.color-dot.blue { background: var(--blue); } .color-dot.red { background: var(--red); } .color-dot.black { background: var(--black); }

.dice-stage { display: flex; align-items: center; justify-content: center; gap: clamp(24px, 3vw, 48px); width: 100%; min-height: 250px; margin: auto 0 2px; perspective: 900px; }
.die-wrap { position: relative; display: flex; flex-direction: column; align-items: center; width: clamp(112px, 10vw, 145px); height: 185px; perspective: 800px; }
.cube { --size: clamp(104px, 9vw, 134px); position: relative; width: var(--size); height: var(--size); margin-top: 16px; transform-style: preserve-3d; transform: rotateX(-11deg) rotateY(17deg); transition: transform .25s ease, filter .25s ease; }
.face { position: absolute; display: grid; place-items: center; width: var(--size); height: var(--size); border: 3px solid rgba(255,255,255,.55); border-radius: 24px; color: white; font-size: clamp(1.75rem, 3vw, 3rem); font-weight: 900; text-shadow: 0 2px 5px rgba(0,0,0,.25); background: linear-gradient(145deg, var(--die-light), var(--die-base) 52%, var(--die-dark)); box-shadow: inset 10px 10px 20px rgba(255,255,255,.12), inset -10px -12px 22px rgba(0,0,0,.2); backface-visibility: hidden; overflow: hidden; }
.face::after { content: ""; position: absolute; inset: -40%; background: linear-gradient(110deg, transparent 35%, rgba(255,255,255,.75) 48%, transparent 59%); transform: translateX(-100%); }
.cube.rolling .face::after { animation: shimmer .55s ease-in-out infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }
.face-front { transform: rotateY(0deg) translateZ(calc(var(--size) / 2)); }
.face-back { transform: rotateY(180deg) translateZ(calc(var(--size) / 2)); }
.face-right { transform: rotateY(90deg) translateZ(calc(var(--size) / 2)); }
.face-left { transform: rotateY(-90deg) translateZ(calc(var(--size) / 2)); }
.face-top { transform: rotateX(90deg) translateZ(calc(var(--size) / 2)); }
.face-bottom { transform: rotateX(-90deg) translateZ(calc(var(--size) / 2)); }
.die-blue { --die-light: #46b4e2; --die-base: #1379b6; --die-dark: #064d83; }
.die-red { --die-light: #ff7a66; --die-base: #e34743; --die-dark: #8f202b; }
.die-black { --die-light: #646a73; --die-base: #333840; --die-dark: #15181e; }
.cube.rolling { animation: tumble .9s cubic-bezier(.15,.65,.25,1); filter: drop-shadow(0 0 18px rgba(90, 203, 244, .65)); }
.dice-stage .die-wrap:last-child .cube.rolling { animation-delay: .05s; }
@keyframes tumble {
  0% { transform: rotateX(-11deg) rotateY(17deg) translateY(0) scale(1); }
  25% { transform: rotateX(185deg) rotateY(230deg) translateY(-42px) scale(1.06); }
  58% { transform: rotateX(460deg) rotateY(515deg) translateY(-10px) scale(.98); }
  100% { transform: rotateX(709deg) rotateY(737deg) translateY(0) scale(1); }
}
.die-shadow { position: absolute; bottom: 36px; width: 80%; height: 22px; border-radius: 50%; background: rgba(19,53,72,.18); filter: blur(8px); }
.cube.rolling + .die-caption, .die-wrap:has(.cube.rolling) .die-shadow { animation: shadow-pulse .9s ease; }
@keyframes shadow-pulse { 45% { opacity: .4; transform: scale(.65); } }
.die-caption { position: absolute; bottom: 0; color: var(--muted); font-size: .73rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.sum-symbol { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 50%; color: var(--blue); background: white; font-size: 1.7rem; font-weight: 700; box-shadow: 0 6px 16px rgba(17, 91, 133, .12); }
.result-card { display: flex; align-items: center; justify-content: space-between; gap: 26px; min-width: 185px; padding: 9px 12px 9px 18px; border: 1px solid #d9ecf4; border-radius: 18px; background: rgba(255,255,255,.85); box-shadow: 0 8px 20px rgba(9, 91, 137, .09); }
.result-card span { color: var(--muted); font-size: .8rem; font-weight: 800; text-transform: uppercase; }
.result-card strong { min-width: 61px; padding: 7px 10px; border-radius: 12px; color: white; background: linear-gradient(135deg, #f18b37, #e84174); font-size: 1.8rem; line-height: 1; text-align: center; }
.result-card.pop strong { animation: result-pop .45s cubic-bezier(.2,.8,.3,1.4); }
@keyframes result-pop { 50% { transform: scale(1.25) rotate(4deg); } }
.roll-button { width: min(310px, 100%); margin-top: 17px; }
.roll-button kbd { margin-left: auto; padding: 3px 7px; border: 1px solid rgba(255,255,255,.3); border-radius: 6px; color: rgba(255,255,255,.8); background: rgba(255,255,255,.12); font-family: inherit; font-size: .65rem; }
.roll-icon { transition: transform .25s ease; } .roll-button:hover .roll-icon { transform: rotate(45deg); }

.timer-panel { position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; background: linear-gradient(160deg, rgba(255,255,255,.95), rgba(255,246,236,.94)); text-align: center; }
.timer-panel::after { content: ""; position: absolute; inset: auto -110px -120px auto; width: 300px; height: 300px; border: 40px solid rgba(248,200,76,.09); transform: rotate(45deg); pointer-events: none; }
.timer-heading { margin-bottom: 17px; }
.time-switch { width: min(260px, 100%); }
.time-option { flex: 1; min-width: 0; padding-inline: 8px; font-size: .78rem; white-space: nowrap; }
.hourglass-wrap { position: relative; width: 250px; height: 350px; margin: auto 0 0; }
.timer-display { position: absolute; z-index: 5; top: 140px; left: 50%; transform: translateX(-50%); min-width: 100px; padding: 8px 13px; border: 3px solid white; border-radius: 16px; color: white; background: var(--ink); box-shadow: 0 8px 18px rgba(24,35,51,.2); font-size: 2rem; font-weight: 900; font-variant-numeric: tabular-nums; }
.hourglass { --hourglass-x: 1; position: absolute; inset: 10px 15px 0; transform-origin: center; }
.hourglass.flipping { animation: flip-hourglass .7s cubic-bezier(.4,.1,.2,1); }
@keyframes flip-hourglass {
  0% { transform: rotate(0deg) scaleX(var(--hourglass-x)); }
  50% { transform: rotate(180deg) scale(.9) scaleX(var(--hourglass-x)); }
  100% { transform: rotate(360deg) scaleX(var(--hourglass-x)); }
}
.hourglass-cap { position: absolute; z-index: 4; left: 15px; width: 190px; height: 25px; border-radius: 10px; background: linear-gradient(#354050, #182333); box-shadow: 0 7px 0 rgba(24,35,51,.1); }
.cap-top { top: 7px; } .cap-bottom { bottom: 7px; }
.hourglass-frame { position: absolute; z-index: 3; top: 24px; width: 15px; height: 286px; border-radius: 9px; background: linear-gradient(90deg,#182333,#4b5665,#182333); }
.frame-left { left: 23px; transform: rotate(-5deg); } .frame-right { right: 23px; transform: rotate(5deg); }
.glass { position: absolute; left: 44px; width: 132px; height: 135px; overflow: hidden; border: 5px solid rgba(126,164,178,.42); background: linear-gradient(90deg, rgba(194,227,237,.4), rgba(255,255,255,.78), rgba(190,224,236,.4)); }
.upper-glass { top: 34px; clip-path: polygon(0 0,100% 0,62% 100%,38% 100%); border-radius: 7px 7px 34px 34px; }
.lower-glass { bottom: 34px; clip-path: polygon(38% 0,62% 0,100% 100%,0 100%); border-radius: 34px 34px 7px 7px; }
.sand { position: absolute; left: 8px; right: 8px; bottom: 5px; min-height: 3px; background: linear-gradient(#f7cf55, #ed8e36); transition: height .9s linear; }
.upper-sand { height: 88%; clip-path: polygon(0 15%,100% 5%,100% 100%,0 100%); }
.lower-sand { height: 3%; clip-path: polygon(50% 0,100% 75%,100% 100%,0 100%,0 75%); }
.sand-stream { display: none; position: absolute; z-index: 2; top: 157px; left: 107px; width: 6px; height: 32px; border-radius: 4px; background: #efaa39; box-shadow: 0 0 8px rgba(239,170,57,.5); animation: stream-flicker .2s linear infinite; }
.hourglass.running .sand-stream { display: block; }
@keyframes stream-flicker { 50% { transform: translateX(1px) scaleX(.7); } }
.timer-status { min-height: 1.45em; margin: 0 0 13px; color: var(--muted); font-size: .84rem; }
.timer-status.finished { color: var(--red); font-weight: 900; animation: pulse-text .7s ease-in-out infinite alternate; }
@keyframes pulse-text { to { transform: scale(1.06); } }
.timer-actions { position: relative; z-index: 4; display: flex; width: min(260px,100%); gap: 9px; }
.timer-button { flex: 1; background: linear-gradient(135deg, #f39a35, #ee5d3c); box-shadow: 0 10px 22px rgba(238,93,60,.2); }
.secondary-button { width: 52px; min-width: 52px; border: 1px solid var(--line); border-radius: 16px; color: var(--ink); background: white; font-size: 1.35rem; }

.footer-tip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 16px auto 0;
  color: var(--muted);
  font-size: .84rem;
  text-align: center;
}
.footer-tip p { margin: 0; }
.footer-tip strong { color: var(--ink); }
.footer-tip b { color: var(--pink); }
.tip-icon { color: var(--orange); font-size: 1.3rem; }

.teacher-popover {
  --arrow-x: 28px;
  --arrow-y: -7px;
  position: fixed;
  z-index: 120;
  display: grid;
  grid-template-columns: 25px minmax(0, 1fr);
  gap: 10px;
  width: min(350px, calc(100vw - 24px));
  padding: 15px 38px 15px 14px;
  border: 1px solid rgba(22, 118, 185, .34);
  border-radius: 18px;
  color: var(--ink);
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 16px 42px rgba(24, 35, 51, .22);
  line-height: 1.4;
  text-align: left;
}
.teacher-popover[hidden] { display: none !important; }
.teacher-popover::before {
  content: "";
  position: absolute;
  left: var(--arrow-x);
  top: var(--arrow-y);
  width: 12px;
  height: 12px;
  border: 1px solid rgba(22, 118, 185, .34);
  background: white;
  transform: rotate(45deg);
}
.teacher-popover[data-placement="bottom"]::before {
  border-right: 0;
  border-bottom: 0;
}
.teacher-popover[data-placement="top"]::before {
  border-top: 0;
  border-left: 0;
}
.teacher-popover[data-placement="right"]::before {
  border-top: 0;
  border-right: 0;
}
.teacher-popover[data-placement="left"]::before {
  border-bottom: 0;
  border-left: 0;
}
.teacher-popover.opening {
  animation: teacher-popover-in .22s cubic-bezier(.2, .85, .3, 1.18);
}
@keyframes teacher-popover-in {
  from { opacity: 0; transform: translateY(5px) scale(.97); }
}
.teacher-popover-icon {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  color: white;
  background: linear-gradient(145deg, var(--blue-light), var(--blue-dark));
  font-family: Georgia, serif;
  font-weight: 900;
}
.teacher-popover strong {
  position: relative;
  z-index: 1;
  display: block;
  padding-top: 2px;
  font-size: .91rem;
}
.teacher-popover p {
  position: relative;
  z-index: 1;
  margin: 4px 0 0;
  color: var(--muted);
  font-size: .82rem;
}
.teacher-popover-close {
  position: absolute;
  z-index: 2;
  top: 7px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}
.teacher-popover-close:hover,
.teacher-popover-close:focus-visible {
  color: var(--ink);
  background: #eef7fc;
}

.rules-dialog { width: min(560px, calc(100% - 32px)); padding: 36px; border: 0; border-radius: 28px; color: var(--ink); background: #fffdf9; box-shadow: 0 30px 100px rgba(24,35,51,.28); }
.rules-dialog::backdrop { background: rgba(24,35,51,.58); backdrop-filter: blur(4px); }
.rules-dialog h2 { margin: 5px 0 20px; font-size: 2rem; }.rules-dialog ol { padding-left: 24px; }.rules-dialog li { margin: 12px 0; padding-left: 6px; line-height: 1.5; }.rules-note { margin: 22px 0; padding: 15px; border-radius: 14px; background: #fff1d8; line-height: 1.5; }.dialog-close { position: absolute; top: 16px; right: 18px; width: 38px; height: 38px; border: 0; border-radius: 50%; color: var(--muted); background: #f3eee7; font-size: 1.6rem; cursor: pointer; }

.celebration { position: fixed; inset: 0; z-index: 100; pointer-events: none; overflow: hidden; }
.confetti { position: absolute; top: -20px; width: 11px; height: 18px; border-radius: 3px; background: var(--confetti); animation: confetti-fall 1.8s ease-in forwards; }
@keyframes confetti-fall { to { transform: translate(var(--drift), 105vh) rotate(720deg); } }

@media (max-width: 1180px) {
  .game-board { grid-template-columns: 1fr 1fr; }
  .cards-panel { grid-column: 1 / -1; min-height: 390px; }
  .cards-stage { min-height: 180px; grid-template-columns: repeat(5, minmax(70px, 120px)); justify-content: center; }
  .number-card { aspect-ratio: 2 / 2.8; }
  .dice-panel, .timer-panel { min-height: 660px; }
}

@media (max-width: 760px) {
  .app-shell { padding: 16px 14px; }
  .topbar { align-items: flex-start; }.classroom-chip { display: none; }.icon-button span:last-child { display: none; }.icon-button { width: 42px; justify-content: center; }
  .game-board { grid-template-columns: 1fr; }
  .panel { min-height: auto; border-radius: 25px; padding: 24px 18px; }
  .cards-panel, .dice-panel, .timer-panel { grid-column: auto; }
  .cards-stage { grid-template-columns: repeat(5, 1fr); gap: 4px; min-height: 200px; }
  .number-card { border-width: 3px; border-radius: 9px; }.number-card::before,.number-card::after { font-size: 7px; letter-spacing: 0; }
  .difficulty-switch { width: 100%; }.difficulty-option { flex: 1; padding: 8px 5px; }.color-dot { display: none; }
  .dice-stage { min-height: 230px; gap: 16px; }.die-wrap { width: 112px; }.sum-symbol { width: 28px; height: 28px; font-size: 1.3rem; }
  .timer-panel { min-height: 620px; }
  .footer-tip { align-items: flex-start; padding: 0 10px; text-align: left; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Układ stołu do gry: karty wysoko, a kości i klepsydra niżej. */
@media (min-width: 901px) {
  .game-board {
    grid-template-columns: repeat(12, minmax(0, 1fr));
    grid-template-rows: auto auto;
    align-items: stretch;
  }

  .panel { min-height: 0; }

  .dice-panel {
    grid-column: 1 / 10;
    grid-row: 2;
    display: grid;
    grid-template-columns: 132px minmax(360px, 1fr) minmax(170px, 205px);
    grid-template-rows: auto 1fr auto;
    gap: 8px 18px;
    min-height: 420px;
    padding: 24px clamp(24px, 3vw, 44px);
  }

  .dice-heading {
    grid-column: 2 / 4;
    grid-row: 1;
  }

  .dice-heading p { margin-bottom: 0; }

  .difficulty-switch {
    grid-column: 1;
    grid-row: 1 / 4;
    align-self: center;
    flex-direction: column;
    width: 132px;
    padding: 7px;
    border-radius: 20px;
  }

  .difficulty-option {
    justify-content: flex-start;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
  }

  .dice-stage {
    grid-column: 2;
    grid-row: 2 / 4;
    min-height: 278px;
    margin: 0;
    gap: clamp(26px, 3.2vw, 56px);
  }

  .die-wrap {
    width: clamp(126px, 11vw, 158px);
    height: 205px;
  }

  .cube { --size: clamp(118px, 10vw, 148px); }

  .result-card {
    grid-column: 3;
    grid-row: 2;
    align-self: center;
    width: 100%;
    min-width: 0;
    gap: 10px;
  }

  .roll-button {
    grid-column: 3;
    grid-row: 3;
    align-self: end;
    width: 100%;
    margin: 0;
    padding-inline: 15px;
  }

  .roll-button kbd { display: none; }

  .timer-panel {
    grid-column: 10 / -1;
    grid-row: 2;
    min-height: 420px;
    padding: 23px 20px;
  }

  .timer-panel h1 { font-size: clamp(1.45rem, 1.8vw, 1.8rem); }
  .timer-heading { margin-bottom: 10px; }
  .time-switch { width: min(245px, 100%); }

  .hourglass-wrap {
    flex: 0 0 auto;
    margin: 10px auto -125px;
    transform: scale(.62);
    transform-origin: top center;
  }

  .timer-status { margin-bottom: 8px; }
  .timer-actions { width: min(220px, 100%); }
  .timer-actions .primary-button { min-height: 48px; padding-inline: 14px; }
  .timer-actions .secondary-button { width: 48px; min-width: 48px; }

  .cards-panel {
    grid-column: 1 / -1;
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76px auto;
    grid-template-rows: auto auto 1fr auto;
    align-items: start;
    column-gap: 30px;
    min-height: 455px;
    padding: 28px clamp(32px, 4vw, 66px) 24px;
  }

  .cards-panel::before { left: -105px; top: 110px; }
  .cards-panel::after { right: -90px; bottom: -100px; }

  .cards-panel .panel-heading {
    grid-column: 1;
    grid-row: 1;
    max-width: 390px;
  }

  .cards-panel .panel-intro {
    grid-column: 1;
    grid-row: 2;
    max-width: 510px;
    margin: 7px 0 0;
  }

  .game-box-figure {
    grid-column: 2;
    grid-row: 1 / 3;
    align-self: center;
    width: 74px;
    margin: 0;
  }

  .cards-stage {
    grid-column: 1 / -1;
    grid-row: 3;
    grid-template-columns: repeat(5, minmax(110px, 1fr));
    align-items: center;
    justify-self: center;
    gap: clamp(22px, 4vw, 74px);
    width: min(1240px, 100%);
    min-height: 305px;
    margin: 0 auto;
    padding: 14px 0 8px;
  }

  .number-card {
    justify-self: center;
    width: min(100%, 178px);
    aspect-ratio: 2 / 2.95;
    border-radius: 16px;
  }

  .card-number { font-size: clamp(3.3rem, 5.2vw, 5.5rem); }
  .card-corner { font-size: clamp(.72rem, 1vw, .9rem); }

  .card-actions {
    grid-column: 3;
    grid-row: 1 / 3;
    align-self: center;
    display: grid;
    grid-template-columns: auto auto;
    justify-content: flex-end;
    justify-items: end;
    margin: 0;
  }

  .deck-mode-wrap {
    grid-column: 1 / -1;
  }

  .deck-mode-button {
    min-height: 33px;
    padding: 7px 12px;
  }

  .helper-text {
    grid-column: 1 / -1;
    grid-row: 4;
    min-height: 0;
    margin: 2px 0 0;
    text-align: center;
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .dice-panel {
    grid-column: 1 / 9;
    grid-template-columns: 112px minmax(300px, 1fr) 158px;
    gap: 8px 12px;
    padding-inline: 22px;
  }

  .timer-panel { grid-column: 9 / -1; }
  .difficulty-switch { width: 112px; }
  .difficulty-option { padding-inline: 8px; font-size: .7rem; }
  .die-wrap { width: 124px; }
  .cube { --size: 116px; }
  .dice-stage { gap: 18px; }
  .result-card { padding-left: 12px; }
  .result-card span { font-size: .7rem; }
  .roll-button { font-size: .78rem; }
  .cards-stage { gap: clamp(16px, 3vw, 38px); }
}

@media (max-width: 900px) {
  .game-board { display: flex; flex-direction: column; }
  .cards-panel { order: 1; }
  .dice-panel { order: 2; }
  .timer-panel { order: 3; }
  .dice-panel, .cards-panel, .timer-panel { min-height: auto; }
  .cards-stage { width: 100%; }
  .timer-panel { min-height: 560px; }
}

@media (max-width: 760px) {
  .dice-panel { min-height: 600px; }
  .cards-panel { min-height: 470px; }
  .timer-panel { min-height: 430px; }
  .hourglass-wrap {
    margin: 6px auto -142px;
    transform: scale(.58);
    transform-origin: top center;
  }
  .timer-status { position: relative; z-index: 4; }
  .timer-actions { position: relative; z-index: 4; }
  .brand-logo { width: 154px; }
  .game-box-figure { width: 74px; }
}

/* Pełnoekranowy widok stołu na laptopach, monitorach i tablicach. */
@media (min-width: 901px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  .app-shell {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    width: min(1600px, 100%);
    height: 100dvh;
    min-height: 0;
    padding: 12px 24px 7px;
    overflow: hidden;
  }

  .topbar {
    min-height: 46px;
    margin-bottom: 8px;
  }

  .brand-logo { width: clamp(172px, 17vw, 214px); }
  .classroom-chip { padding: 8px 12px; }
  .icon-button { min-height: 38px; padding-block: 6px; }

  .game-board {
    height: 100%;
    min-height: 0;
    grid-template-rows: minmax(0, 54%) minmax(0, 46%);
    gap: 12px;
  }

  .panel {
    height: 100%;
    min-height: 0;
    border-radius: 27px;
  }

  .panel h1 { font-size: clamp(1.45rem, 2vw, 2rem); }

  .dice-panel {
    grid-template-columns: 112px minmax(280px, 1fr) minmax(145px, 185px);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 4px 12px;
    min-height: 0;
    padding: 13px clamp(17px, 2.2vw, 34px);
  }

  .dice-heading p {
    margin-top: 5px;
    font-size: .78rem;
  }

  .difficulty-switch {
    width: 112px;
    padding: 5px;
    border-radius: 17px;
  }

  .difficulty-option {
    min-height: 37px;
    padding: 7px 8px;
    font-size: .7rem;
  }

  .dice-stage {
    min-height: 0;
    height: 100%;
    gap: clamp(15px, 2.4vw, 38px);
  }

  .die-wrap {
    width: clamp(104px, 13vh, 142px);
    height: clamp(137px, 21vh, 190px);
  }

  .cube {
    --size: clamp(96px, 13vh, 136px);
    margin-top: 10px;
  }

  .face {
    border-radius: clamp(17px, 2vh, 23px);
    font-size: clamp(1.65rem, 5.4vh, 2.8rem);
  }

  .die-shadow { bottom: 30px; }
  .die-caption { bottom: 1px; font-size: .67rem; }

  .result-card {
    position: relative;
    z-index: 4;
    grid-column: 2 / 4;
    grid-row: 2;
    justify-self: end;
    width: min(300px, 100%);
    min-height: 86px;
    padding: 11px 12px 11px 24px;
    border-radius: 24px;
    box-shadow: 0 14px 32px rgba(9, 91, 137, .14);
  }

  .result-card span { font-size: 1.08rem; }
  .result-card strong {
    min-width: 94px;
    padding: 12px 15px;
    border-radius: 18px;
    font-size: 3.05rem;
  }

  .dice-stage .die-wrap:last-child .die-caption { display: none; }

  .roll-button {
    position: relative;
    z-index: 5;
    grid-column: 2 / 4;
    justify-self: center;
    width: min(420px, 100%);
    min-height: 64px;
    padding: 14px 28px;
    border-radius: 20px;
    font-size: clamp(1.12rem, 1.8vw, 1.48rem);
    letter-spacing: .01em;
    box-shadow: 0 14px 30px rgba(9, 89, 145, .3);
  }

  .roll-button .roll-icon { font-size: 1.15em; }

  .timer-panel {
    min-height: 0;
    padding: 8px 12px;
  }

  .timer-panel h1 { font-size: clamp(1.16rem, 1.5vw, 1.48rem); }
  .timer-heading { margin-bottom: 3px; }
  .timer-heading .eyebrow { font-size: .58rem; }
  .time-switch { width: min(240px, 100%); padding: 4px; gap: 4px; }
  .time-option { min-height: 30px; padding: 4px 6px; font-size: .68rem; }

  .hourglass-wrap {
    margin: 0 auto -168px;
    transform: scale(.52);
    transform-origin: top center;
  }

  .hourglass {
    --hourglass-x: 1.22;
    transform: scaleX(var(--hourglass-x));
  }

  .timer-display {
    top: 119px;
    min-width: 170px;
    padding: 12px 18px;
    border-width: 5px;
    border-radius: 22px;
    font-size: 4.5rem;
    line-height: 1;
    box-shadow: 0 12px 28px rgba(24, 35, 51, .3);
  }

  .sand-stream {
    left: 105px;
    width: 10px;
    box-shadow: 0 0 14px rgba(239, 170, 57, .8);
  }

  .timer-status {
    min-height: 1.2em;
    margin: 0 0 3px;
    font-size: .64rem;
  }

  .timer-actions { width: min(205px, 100%); }
  .timer-actions .primary-button { min-height: 43px; padding-block: 9px; }
  .timer-actions .secondary-button { width: 43px; min-width: 43px; min-height: 43px; }

  .cards-panel {
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    min-height: 0;
    padding: 14px clamp(26px, 3.2vw, 50px) 10px;
  }

  .cards-panel .panel-heading { max-width: 350px; }
  .cards-panel .panel-intro {
    margin-top: 3px;
    font-size: .82rem;
    line-height: 1.3;
  }

  .deck-counter { padding: 7px 10px; }
  .mini-deck { width: 18px; height: 24px; }

  .cards-stage {
    height: 100%;
    min-height: 0;
    gap: clamp(13px, 3vw, 48px);
    padding: 2px 0;
  }

  .number-card {
    width: min(100%, clamp(104px, 17vh, 180px));
    max-height: 100%;
    aspect-ratio: 2 / 2.95;
    border-width: 3px;
    border-radius: 13px;
  }

  .number-card::before,
  .number-card::after {
    height: 22px;
    font-size: 8px;
    line-height: 20px;
  }

  .card-corner { font-size: clamp(.6rem, 1.7vh, .82rem); }
  .card-corner.top { top: 22px; }
  .card-corner.bottom { bottom: 22px; }
  .card-number { font-size: clamp(2.7rem, 7vh, 4.75rem); }

  .card-actions { gap: 8px; }
  .card-actions .primary-button { min-height: 45px; padding: 10px 16px; }
  .card-actions .text-button { padding-inline: 5px; }
  .deck-mode-button { font-size: .68rem; }

  .helper-text {
    margin-top: 0;
    font-size: .68rem;
    line-height: 1.2;
  }

  .footer-tip {
    min-height: 19px;
    margin: 5px auto 0;
    font-size: .71rem;
  }

  .tip-icon { font-size: 1rem; }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .dice-panel {
    grid-template-columns: 98px minmax(250px, 1fr) 135px;
    gap-inline: 8px;
    padding-inline: 14px;
  }

  .difficulty-switch { width: 98px; }
  .difficulty-option { padding-inline: 6px; font-size: .64rem; }
  .color-dot { width: 8px; height: 8px; }
  .result-card { padding-left: 8px; }
  .roll-button {
    min-height: 58px;
    padding-inline: 18px;
    font-size: 1rem;
  }
  .cards-panel { padding-inline: 32px; }
}

@media (min-width: 901px) {
  .die-caption {
    top: 50%;
    bottom: auto;
    padding: 3px 7px;
    border: 1px solid rgba(22, 118, 185, .1);
    border-radius: 999px;
    background: rgba(255, 255, 255, .7);
    white-space: nowrap;
  }

  .dice-stage .die-wrap:first-child .die-caption {
    right: auto;
    left: -3px;
    transform: translate(-100%, -50%) rotate(-90deg);
  }

  .dice-stage .die-wrap:last-child .die-caption {
    right: -3px;
    left: auto;
    transform: translate(100%, -50%) rotate(90deg);
  }

  .cube.rolling + .die-caption { animation: none; }
}

/* Szkliste, przestrzenne wykończenie kostek. */
.die-wrap::before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 18%;
  left: 50%;
  width: 112%;
  height: 72%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(69, 190, 239, .32), rgba(73, 162, 219, .1) 42%, transparent 72%);
  filter: blur(14px);
  opacity: .8;
  transform: translateX(-50%);
  transition: opacity .25s ease, transform .25s ease;
}

.cube {
  z-index: 2;
  filter: none;
  will-change: transform;
}

.face {
  border-color: rgba(222, 246, 255, .78);
  background:
    radial-gradient(circle at 25% 16%, rgba(255, 255, 255, .58) 0 3%, rgba(191, 238, 255, .22) 14%, transparent 31%),
    linear-gradient(155deg, rgba(255, 255, 255, .22), transparent 33%),
    linear-gradient(132deg, var(--die-light) 0%, var(--die-base) 46%, var(--die-dark) 100%);
  box-shadow:
    inset 2px 2px 2px rgba(255, 255, 255, .72),
    inset 12px 10px 22px rgba(255, 255, 255, .13),
    inset -13px -15px 25px rgba(0, 23, 48, .3),
    inset 0 0 0 1px rgba(0, 43, 78, .18),
    0 0 12px rgba(92, 205, 246, .14);
  text-shadow:
    0 2px 2px rgba(0, 24, 53, .35),
    0 5px 12px rgba(0, 31, 65, .24),
    0 0 11px rgba(255, 255, 255, .2);
}

.face::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background:
    linear-gradient(118deg, rgba(255, 255, 255, .42), transparent 20% 65%, rgba(120, 220, 255, .2)),
    radial-gradient(ellipse at 72% 82%, rgba(80, 196, 255, .22), transparent 42%);
  mix-blend-mode: screen;
  opacity: .72;
  pointer-events: none;
}

.face::after {
  inset: -55%;
  background: linear-gradient(
    112deg,
    transparent 29%,
    rgba(126, 224, 255, .08) 37%,
    rgba(255, 255, 255, .94) 47%,
    rgba(255, 211, 245, .58) 52%,
    rgba(113, 220, 255, .22) 58%,
    transparent 68%
  );
  transform: translateX(-112%) rotate(7deg);
}

.face-top::before {
  background: linear-gradient(145deg, rgba(255, 255, 255, .55), rgba(169, 229, 255, .13));
  mix-blend-mode: screen;
}

.face-left::before {
  background: linear-gradient(120deg, rgba(0, 24, 58, .42), rgba(17, 83, 129, .1));
  mix-blend-mode: multiply;
}

.face-right::before {
  background: linear-gradient(120deg, rgba(0, 31, 67, .25), transparent 70%);
  mix-blend-mode: multiply;
}

.face-back::before,
.face-bottom::before {
  background: rgba(0, 26, 58, .32);
  mix-blend-mode: multiply;
}

.die-shadow {
  background: radial-gradient(ellipse, rgba(5, 48, 78, .34), rgba(13, 91, 133, .12) 48%, transparent 72%);
  filter: blur(7px);
  transform: scaleX(1.08);
}

.cube.rolling {
  animation: tumble .95s cubic-bezier(.14, .7, .2, 1);
  filter: none;
}

.cube.rolling .face {
  animation: dice-surface-glow .34s ease-in-out infinite alternate;
}

.cube.rolling .face::before {
  animation: spectral-pulse .42s ease-in-out infinite alternate;
}

.cube.rolling .face::after {
  animation: shimmer .36s ease-in-out infinite;
}

.die-wrap:has(.cube.rolling)::before {
  animation: halo-pulse .48s ease-in-out infinite alternate;
}

@keyframes shimmer {
  from { transform: translateX(-112%) rotate(7deg); }
  to { transform: translateX(112%) rotate(7deg); }
}

@keyframes dice-surface-glow {
  from {
    box-shadow:
      inset 2px 2px 2px rgba(255, 255, 255, .68),
      inset 12px 10px 22px rgba(255, 255, 255, .12),
      inset -13px -15px 25px rgba(0, 23, 48, .3),
      0 0 8px rgba(80, 203, 246, .2);
  }
  to {
    box-shadow:
      inset 4px 4px 5px rgba(255, 255, 255, .92),
      inset 16px 12px 26px rgba(184, 239, 255, .24),
      inset -10px -12px 22px rgba(0, 23, 48, .2),
      0 0 22px rgba(109, 218, 255, .66);
  }
}

@keyframes spectral-pulse {
  from { opacity: .48; filter: hue-rotate(0deg); }
  to { opacity: 1; filter: hue-rotate(28deg); }
}

@keyframes halo-pulse {
  from { opacity: .48; transform: translateX(-50%) scale(.88); }
  to { opacity: 1; transform: translateX(-50%) scale(1.12); }
}

@keyframes tumble {
  0% { transform: rotateX(-11deg) rotateY(17deg) translateY(0) scale(1); }
  28% { transform: rotateX(190deg) rotateY(230deg) translateY(-11px) scale(1.04); }
  60% { transform: rotateX(470deg) rotateY(520deg) translateY(-4px) scale(.99); }
  84% { transform: rotateX(665deg) rotateY(690deg) translateY(-7px) scale(1.02); }
  100% { transform: rotateX(709deg) rotateY(737deg) translateY(0) scale(1); }
}

@media (min-width: 901px) {
  .timer-panel {
    display: grid;
    grid-template-columns: minmax(76px, .75fr) minmax(145px, 1.25fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 0 8px;
    padding: 8px 12px;
  }

  .timer-heading {
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    margin: 0;
    text-align: left;
  }

  .timer-heading .eyebrow { display: none; }
  .timer-panel h1 { margin: 0; font-size: clamp(1rem, 1.35vw, 1.3rem); }
  .timer-heading .title-with-info { gap: 5px; }
  .timer-heading .info-trigger { width: 20px; height: 20px; font-size: .7rem; }

  .time-switch {
    grid-column: 2;
    grid-row: 1;
    width: 100%;
    min-width: 0;
  }

  .hourglass-wrap {
    grid-column: 1 / -1;
    grid-row: 2;
    align-self: center;
    justify-self: center;
    margin: 0 auto -168px;
    transform: scale(.52);
    transform-origin: top center;
  }

  .timer-status {
    grid-column: 1;
    grid-row: 3;
    align-self: center;
    max-width: 84px;
    margin: 0;
    font-size: .61rem;
    line-height: 1.08;
    text-align: left;
  }

  .timer-actions {
    grid-column: 2;
    grid-row: 3;
    justify-self: stretch;
    width: 100%;
  }
}
