/* The screen of a party game (templates/games/play.html): one screen on a tablet, a computer or a
   phone, readable from the sofa. Light or dark after the visitor's setting. Colour pairs are
   checked by calculation (WCAG AA); the numbers are beside them. */
:root {
  --bg: #F8F5EE;
  --surface: #FFFFFF;
  --ink: #1C2B22;        /* 13.6:1 on --bg */
  --muted: #4C5A51;      /* 6.7:1 on --bg, 7.3:1 on --surface */
  --line: #CFC8B6;
  --red: #B3202A;        /* white text on it 6.7:1; 6.1:1 on --bg */
  --red-dark: #8A141D;
  --green: #1F5B3A;      /* 7.4:1 on --bg */
  --turn: #FBE7B0;       /* --ink on it 12.1:1 */
  --turn-edge: #B3202A;  /* the current player's edge and arrow: 5.4:1 on --turn */
  --alert: #B3202A;      /* the last half minute: 7.2:1 on --surface */
  --focus: #1A5FB4;      /* 5.8:1 on --bg */
  --shade: rgba(16, 34, 24, 0.74);
  --flake: #E4EBE5;
  --serif: 'Fraunces', Georgia, serif;
  --hand: 'Caveat', cursive;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F2218;
    --surface: #18382A;
    --ink: #F5F0E4;      /* 14.6:1 on --bg, 11.3:1 on --surface */
    --muted: #C3CEC6;    /* 10.3:1 on --bg, 7.9:1 on --surface */
    --line: #3F5E4D;
    --red: #C8323D;      /* white text on it 5.3:1; 3.2:1 on --bg */
    --red-dark: #A3212B;
    --green: #8FD1A8;    /* 9.4:1 on --bg, 7.2:1 on --surface */
    --turn: #3B3416;     /* --ink on it 10.9:1 */
    --turn-edge: #F2C14E; /* 7.4:1 on --turn */
    --alert: #FF8A8A;    /* 5.7:1 on --surface */
    --focus: #8DB7FF;    /* 8.2:1 on --bg */
    --shade: rgba(4, 12, 8, 0.8);
    --flake: #1D3A2B;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body.game-screen {
  background: var(--bg);
  color: var(--ink);
  font-family: 'DM Sans', system-ui, sans-serif;
  font-size: clamp(17px, 2.2vmin, 30px);
  line-height: 1.35;
  background-image:
    radial-gradient(circle at 20px 30px, var(--flake) 0 3px, transparent 4px),
    radial-gradient(circle at 170px 110px, var(--flake) 0 4px, transparent 5px),
    radial-gradient(circle at 290px 220px, var(--flake) 0 3px, transparent 4px),
    radial-gradient(circle at 90px 330px, var(--flake) 0 2px, transparent 3px);
  background-size: 400px 400px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}
body.game-screen::before { content: ""; display: block; flex: none; height: 10px; background: repeating-linear-gradient(135deg, #B3202A 0 14px, #FFFFFF 14px 28px); }
h1, h2, p, ol, ul { margin: 0; }
h1, h2 { font-family: var(--serif); line-height: 1.08; }
[hidden] { display: none !important; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; border-radius: 6px; }
.g-visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* top bar */
.g-top { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px clamp(12px, 2vw, 32px); }
.g-brand { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; color: var(--ink); text-decoration: none; font-weight: 700; }
.g-brand:hover span { text-decoration: underline; }
.g-badge { padding: 4px 12px; border-radius: 999px; background: var(--green); color: var(--bg); font-weight: 700; font-size: 0.85em; }
.g-tools { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.g-tool { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 6px 14px; font: inherit; font-size: 0.85em; font-weight: 700; color: var(--ink); background: transparent; border: 2px solid var(--muted); border-radius: 999px; cursor: pointer; }
.g-tool:hover { border-color: var(--ink); }
.g-tool[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.g-tool[data-sound] .g-mute, .g-tool[data-sound][aria-pressed="true"] .g-wave { display: inline; }
.g-tool[data-sound] .g-wave, .g-tool[data-sound][aria-pressed="true"] .g-mute { display: none; }
.g-tool[data-sound][aria-pressed="false"] { background: transparent; color: var(--ink); }

.g-main { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; padding: 0 clamp(12px, 2.4vw, 48px) clamp(12px, 2vh, 32px); }

/* buttons */
.g-btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; min-height: 56px; padding: 10px 26px; font: inherit; font-weight: 700; color: #FFFFFF; background: var(--red); border: 2px solid var(--red); border-radius: 999px; cursor: pointer; text-decoration: none; text-align: center; }
.g-btn:hover { background: var(--red-dark); border-color: var(--red-dark); }
.g-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.g-btn-big { min-height: 72px; padding: 14px 40px; font-size: 1.25em; }
.g-btn-ghost { background: transparent; color: var(--ink); border-color: var(--ink); }
.g-btn-ghost:hover { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.g-link { font: inherit; color: var(--ink); background: none; border: none; text-decoration: underline; min-height: 44px; cursor: pointer; }
.g-step { width: 56px; height: 56px; flex: none; font: inherit; font-size: 1.5em; font-weight: 700; line-height: 1; color: var(--ink); background: var(--surface); border: 2px solid var(--ink); border-radius: 50%; cursor: pointer; }
.g-step:hover { background: var(--ink); color: var(--bg); }
.g-small { font-size: 0.85em; color: var(--muted); }

/* setting up */
.g-setup { width: 100%; max-width: 820px; margin: 0 auto; padding-top: clamp(8px, 3vh, 48px); display: flex; flex-direction: column; gap: 18px; }
.g-setup h1 { font-size: clamp(40px, 7vmin, 96px); }
.g-lead { font-size: 1.15em; color: var(--muted); }
.g-add label { display: block; font-weight: 700; margin-bottom: 6px; }
.g-add-row { display: flex; gap: 10px; }
.g-add input { flex: 1 1 auto; min-width: 0; min-height: 60px; padding: 8px 18px; font: inherit; font-size: 1.2em; color: var(--ink); background: var(--surface); border: 2px solid var(--muted); border-radius: 14px; }
.g-add input:focus-visible { border-color: var(--focus); }
/* A die inside the field for a player's name. */
.g-add input { padding-left: 58px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' stroke='%231C2B22' stroke-width='1.3' stroke-linejoin='round'%3E%3Crect x='3.5' y='3.5' width='17' height='17' rx='4' fill='%23B3202A'/%3E%3Cg fill='%23FFFFFF' stroke='none'%3E%3Ccircle cx='8.5' cy='8.5' r='1.6'/%3E%3Ccircle cx='15.5' cy='8.5' r='1.6'/%3E%3Ccircle cx='12' cy='12' r='1.6'/%3E%3Ccircle cx='8.5' cy='15.5' r='1.6'/%3E%3Ccircle cx='15.5' cy='15.5' r='1.6'/%3E%3C/g%3E%3C/svg%3E") no-repeat 18px center / 28px 28px; }
.g-add input::placeholder { color: var(--muted); opacity: 1; }
.g-names { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 10px; min-height: 56px; counter-reset: seat; }
.g-names li { display: inline-flex; align-items: center; gap: 4px; padding: 4px 4px 4px 16px; background: var(--surface); border: 2px solid var(--line); border-radius: 999px; font-weight: 700; counter-increment: seat; }
.g-names li::before { content: counter(seat) "."; color: var(--muted); margin-right: 6px; font-weight: 400; }
.g-remove { width: 44px; height: 44px; font: inherit; font-size: 1.3em; line-height: 1; color: var(--ink); background: transparent; border: none; border-radius: 50%; cursor: pointer; }
.g-remove:hover { background: var(--line); }
.g-minutes { display: flex; align-items: center; gap: 14px; font-weight: 700; }
.g-minutes output { min-width: 4.5em; text-align: center; font-size: 1.3em; font-variant-numeric: tabular-nums; }
.g-note { padding: 14px 18px; border-left: 6px solid var(--green); background: var(--surface); border-radius: 8px; }
.g-setup [data-start] { align-self: flex-start; }

/* playing */
.g-play { flex: 1 1 auto; display: flex; flex-direction: column; gap: clamp(8px, 2vh, 28px); min-height: 0; }
.g-bar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 28px; min-height: clamp(56px, 9vh, 130px); }
.g-round { font-family: var(--serif); font-weight: 700; font-size: clamp(22px, 3.6vmin, 56px); }
.g-pile { font-size: clamp(18px, 2.6vmin, 40px); color: var(--muted); font-weight: 700; }
.g-clock { margin-left: auto; display: flex; align-items: center; gap: 14px; padding: 6px 10px 6px 22px; background: var(--surface); border: 3px solid var(--green); border-radius: 999px; }
.g-clock:has(.g-pause[hidden]) { padding-right: 22px; }
.g-clock-label { font-weight: 700; color: var(--muted); }
.g-clock-time { font-family: var(--serif); font-weight: 700; font-size: clamp(40px, 8vmin, 140px); line-height: 1; font-variant-numeric: tabular-nums; min-width: 3.1ch; text-align: right; }
.g-clock.is-low { border-color: var(--alert); }
.g-clock.is-low .g-clock-time { color: var(--alert); }
.g-pause .g-icon-play, .g-pause[aria-pressed="true"] .g-icon-pause { display: none; }
.g-pause[aria-pressed="true"] .g-icon-play { display: inline; }

.g-stage { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: clamp(16px, 3vw, 64px); align-items: center; min-height: 0; }
.g-turn { display: flex; flex-direction: column; align-items: center; gap: clamp(6px, 1.6vh, 20px); text-align: center; }
.g-turn-label { font-size: clamp(18px, 2.8vmin, 44px); color: var(--muted); font-weight: 700; }
.g-turn-name { font-family: var(--serif); font-weight: 700; font-size: clamp(40px, 9vmin, 150px); line-height: 1; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-message { min-height: 2.7em; display: flex; align-items: center; justify-content: center; font-size: clamp(18px, 3vmin, 46px); font-weight: 700; max-width: 26em; }
/* With a real die (the choice at the start, or the tool "Riktig tärning") the screen's die goes
   and two big buttons take its place: the player who rolled taps what it showed. */
.g-real { display: none; flex-direction: column; align-items: center; gap: clamp(8px, 1.6vmin, 20px); width: 100%; }
.g-real-row { display: flex; flex-wrap: wrap; justify-content: center; gap: clamp(10px, 2vmin, 28px); width: 100%; }
.g-real .g-btn { flex: 1 1 10em; max-width: 14em; min-height: clamp(72px, 13vmin, 180px); font-size: clamp(22px, 4.4vmin, 64px); border-width: 3px; }
.is-real-die .g-real { display: flex; }
.is-real-die .g-die, .is-real-die .g-roll-hint { display: none; }
/* A phone or a tablet has no space bar to press. */
@media (hover: none) { .g-keys { display: none; } }
.g-dice-choice { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-weight: 700; }
.g-dice-choice span { margin-right: 4px; }
.g-choice { min-height: 48px; padding: 8px 18px; font: inherit; font-weight: 700; color: var(--ink); background: var(--surface); border: 2px solid var(--ink); border-radius: 999px; cursor: pointer; }
.g-choice[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* the die: nine places for pips, of which a face shows some */
.g-die { margin-bottom: 1.4vmin; padding: 0; border: none; background: none; cursor: pointer; border-radius: 22%; }
.g-die:disabled { cursor: default; }
.g-face { width: clamp(130px, 28vmin, 380px); aspect-ratio: 1; display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 14%; gap: 4%; background: #FFFFFF; border: clamp(4px, 0.8vmin, 10px) solid #B3202A; border-radius: 22%; box-shadow: 0 1.2vmin 0 #8A141D, 0 2vmin 4vmin rgba(0, 0, 0, 0.25); }
.g-die:hover .g-face { transform: translateY(-2px); }
.g-die:disabled .g-face { opacity: 0.55; }
.g-face i { display: block; border-radius: 50%; background: #1C2B22; transform: scale(0.82); visibility: hidden; }
.g-face[data-face="1"] i:nth-child(5),
.g-face[data-face="2"] i:is(:nth-child(1), :nth-child(9)),
.g-face[data-face="3"] i:is(:nth-child(1), :nth-child(5), :nth-child(9)),
.g-face[data-face="4"] i:is(:nth-child(1), :nth-child(3), :nth-child(7), :nth-child(9)),
.g-face[data-face="5"] i:is(:nth-child(1), :nth-child(3), :nth-child(5), :nth-child(7), :nth-child(9)),
.g-face[data-face="6"] i:is(:nth-child(1), :nth-child(3), :nth-child(4), :nth-child(6), :nth-child(7), :nth-child(9)) { visibility: visible; }
.g-face[data-face="6"] i { background: #B3202A; }
.g-face.is-rolling { animation: tumble 0.6s linear; }
@keyframes tumble { 0% { transform: rotate(0); } 25% { transform: rotate(-14deg) translateY(-6%); } 50% { transform: rotate(10deg); } 75% { transform: rotate(-6deg) translateY(-3%); } 100% { transform: rotate(0); } }
.g-die.is-six .g-face { animation: pop 0.5s ease-out; }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.12) rotate(4deg); } 100% { transform: scale(1); } }

/* the players, in the order they sit */
.g-players { list-style: none; padding: 0; display: grid; gap: clamp(6px, 1vh, 12px); align-content: center; font-size: clamp(18px, 3.2vmin, 48px); }
.g-players.is-many { grid-template-columns: repeat(2, minmax(0, 1fr)); font-size: clamp(15px, 2.2vmin, 34px); }
.g-player { display: flex; align-items: center; gap: 0.4em; min-height: 1.9em; padding: 0.2em 0.5em; background: var(--surface); border: 3px solid var(--line); border-radius: 0.5em; }
.g-player.is-turn { background: var(--turn); border-color: var(--turn-edge); }
.g-mark { flex: none; width: 1em; color: var(--turn-edge); visibility: hidden; font-size: 0.8em; }
.g-player.is-turn .g-mark { visibility: visible; }
.g-who { flex: 1 1 auto; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-gifts { flex: none; display: inline-flex; gap: 0.12em; }
/* A gift: wrapping paper and a ribbon across, in six wrappings (data-wrap, from julklapp.js). */
.g-gifts i { --paper: #B3202A; --ribbon: #E8B94A; display: block; width: 0.8em; height: 0.8em; border-radius: 0.12em; background: linear-gradient(90deg, transparent 40%, var(--ribbon) 40% 60%, transparent 60%), linear-gradient(transparent 40%, var(--ribbon) 40% 60%, transparent 60%), var(--paper); }
.g-gifts i[data-wrap="1"] { --paper: #1F5B3A; --ribbon: #E8B94A; }
.g-gifts i[data-wrap="2"] { --paper: #E8B94A; --ribbon: #B3202A; }
.g-gifts i[data-wrap="3"] { --paper: #2A5DA8; --ribbon: #E6ECF5; }
.g-gifts i[data-wrap="4"] { --paper: #6B3FA0; --ribbon: #F2C94C; }
.g-gifts i[data-wrap="5"] { --paper: #F4EFE6; --ribbon: #B3202A; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.g-count { flex: none; min-width: 1.6em; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.g-players.is-fixing .g-step { width: 1.6em; height: 1.6em; font-size: 0.8em; }

/* panels over the game */
.g-overlay { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--shade); overflow: auto; }
.g-panel { width: min(100%, 1100px); max-height: 100%; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: clamp(12px, 2.4vh, 32px); padding: clamp(20px, 4vmin, 64px); text-align: center; background: var(--surface); color: var(--ink); border-radius: 28px; box-shadow: 0 2vmin 8vmin rgba(0, 0, 0, 0.4); font-size: clamp(18px, 3vmin, 42px); }
.g-panel h2 { font-size: clamp(32px, 6.5vmin, 110px); }
/* "Ny lek": a question, so narrower than the game's panels. */
.g-ask { width: min(100%, 760px); }
.g-choices { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.g-choices .g-btn { font-size: 1em; }
.g-hand { font-family: var(--hand); font-size: 1.5em; color: var(--alert); }
.g-result { list-style: none; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 24px; font-weight: 700; }

/* a card from the elf: the same card in both themes, like the printed ones */
.g-card { --surface: #FFFDF7; --ink: #1C2B22; --muted: #4C5A51; --red: #B3202A; --red-dark: #8A141D; position: relative; overflow: hidden; border: clamp(5px, 0.8vmin, 10px) solid #B3202A; padding-bottom: calc(clamp(20px, 4vmin, 64px) + 24px); }
.g-card::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 22px; background: repeating-linear-gradient(135deg, #B3202A 0 12px, #FFFFFF 12px 24px); }
.g-card-elf { width: clamp(64px, 12vmin, 160px); height: auto; }
.g-card-tag { font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; font-size: 0.7em; color: #1F5B3A; }
.g-card .g-card-tag { color: #1F5B3A; }
.g-card-text { font-family: var(--hand); font-weight: 700; font-size: clamp(36px, 7vmin, 112px); line-height: 1.1; max-width: 18em; }
.g-card-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin: 0; }
.g-card .g-btn-ghost:hover { color: #FFFDF7; }
.g-panel:not(.g-card) .g-card-tag { color: var(--green); }

.g-bells svg { width: clamp(120px, 20vmin, 300px); height: auto; }
.is-ringing .g-bells svg { animation: ring 0.5s ease-in-out 6; transform-origin: 50% 10%; }
@keyframes ring { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-12deg); } 75% { transform: rotate(12deg); } }

.g-buy h2 { font-size: clamp(28px, 5vmin, 80px); max-width: 20em; }

/* A phone: one column, and the page may scroll. */
@media (max-width: 760px) {
  .g-stage { flex: none; grid-template-columns: minmax(0, 1fr); align-items: start; }
  .g-clock { margin-left: auto; margin-right: auto; }
  .g-players.is-many { grid-template-columns: minmax(0, 1fr); }
  .g-tool span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .g-tool { padding: 6px 10px; }
  .g-add-row { flex-wrap: wrap; }
  .g-add-row .g-btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  .g-face.is-rolling, .g-die.is-six .g-face, .is-ringing .g-bells svg { animation: none; }
  .g-die:hover .g-face { transform: none; }
}
