/* ---- The Yatzy table ---- */
/* Everything here lives inside #yatzy, which yatzy.js fills. The colours of
   the page come from style.css; the tray, the dice and the score sheet have
   their own: parchment, dark green and gold. */
#yatzy { max-width: 560px; margin: 0 auto; --yz-gold: #c9a24b; --yz-gold-lit: #e2c170; --yz-green: #173d2c; --yz-paper: #f3ead6; --yz-paper-dark: #e2d6b8; --yz-ink: #2b2113; --yz-serif: Georgia, 'Times New Roman', serif; }
#yatzy #yz-title { text-align: center; font-weight: 700; font-size: 0.9rem; padding: 0 48px; min-height: 1.3em; margin-bottom: 6px; }

/* One column: the players, whose go it is, the dice, the sheet. (On a wide screen: see the end.) */
#yatzy #yz-main { display: flex; flex-direction: column; }
#yatzy #yz-left, #yatzy #yz-side { display: contents; }
#yatzy #yz-players { order: 1; }
#yatzy #yz-status { order: 2; }
#yatzy #yz-tray { order: 3; }
#yatzy #yz-roll { order: 4; }
#yatzy #yz-timer { order: 5; }
#yatzy #yz-last { order: 6; }
#yatzy #yz-error { order: 7; }
#yatzy #yz-setup { order: 8; }
#yatzy #yz-result { order: 9; }
#yatzy #yz-card { order: 10; }
#yatzy #yz-hint { order: 11; }

/* The four players: ruby, sapphire, gold and emerald. */
#yatzy .yz-c0 { --yz-col: #a3283c; --yz-on: #fff; }
#yatzy .yz-c1 { --yz-col: #2f5597; --yz-on: #fff; }
#yatzy .yz-c2 { --yz-col: #c99a2e; --yz-on: #1b1b1b; }
#yatzy .yz-c3 { --yz-col: #1f7a5a; --yz-on: #fff; }

/* The players. */
#yatzy #yz-players { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#yatzy .yz-player { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 48px; padding: 3px 7px 3px 6px; border-radius: 10px; border: 1px solid var(--t0); border-left: 5px solid var(--yz-col); background: rgba(0, 0, 0, 0.18); }
#yatzy .yz-player.yz-turn { border-color: var(--accent); border-left-color: var(--yz-col); background: rgba(255, 255, 255, 0.08); box-shadow: 0 0 0 1px var(--accent); }
#yatzy .yz-player.yz-won { border-color: var(--t15); border-left-color: var(--yz-col); }
#yatzy .yz-player.yz-empty { opacity: 0.55; border-style: dashed; border-left-style: solid; }
#yatzy .yz-player.yz-vacant { opacity: 1; cursor: pointer; }
#yatzy .yz-player.yz-vacant .yz-name { text-decoration: underline; }
#yatzy .yz-dot { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--yz-col); color: var(--yz-on); font: 700 0.82rem var(--yz-serif); box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75), 0 1px 3px rgba(0, 0, 0, 0.5); }
#yatzy .yz-empty .yz-dot { opacity: 0.5; box-shadow: none; }
#yatzy .yz-who { flex: 1; min-width: 0; }
#yatzy .yz-name { font-weight: 700; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#yatzy .yz-empty .yz-name { font-weight: 400; font-size: 0.8rem; white-space: normal; }
#yatzy .yz-info { font-size: 0.72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
/* The camera picture: round, and shown as the others see it, never mirrored. */
#yatzy .yz-cam { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #000; box-shadow: 0 0 0 2px var(--yz-col); flex: none; transform: none; }
#yatzy .yz-cam.blank { display: none; }
#yatzy .yz-clock { flex: none; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.85rem; padding: 2px 6px; border-radius: 8px; background: #f4f4f4; color: #111; }
#yatzy .yz-clock.yz-low { background: #d93025; color: #fff; }

/* Table talk: a speech bubble under a player's box. */
#yatzy .yz-bubble { position: absolute; left: 8px; top: calc(100% + 4px); z-index: 6; width: max-content; max-width: min(300px, 78vw); background: #fdfdfd; color: #161616; border-radius: 12px; padding: 7px 11px; font-size: 0.88rem; font-weight: 600; line-height: 1.25; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5); pointer-events: none; }
#yatzy .yz-bubble::after { content: ''; position: absolute; left: 18px; top: -12px; border: 6px solid transparent; border-bottom-color: #fdfdfd; }
#yatzy .yz-player:nth-child(even) .yz-bubble { left: auto; right: 8px; }
#yatzy .yz-player:nth-child(even) .yz-bubble::after { left: auto; right: 18px; }
#yatzy .yz-bubble.yz-pop { animation: yz-pop 0.22s ease-out; }
@keyframes yz-pop { from { transform: scale(0.7); opacity: 0; } }

/* Whose go it is, and what just happened. */
#yatzy #yz-status { text-align: center; font-weight: 700; min-height: 1.5em; margin: 8px 0 0; }
#yatzy #yz-status.yz-go { color: var(--accent); }
#yatzy #yz-last { text-align: center; font-size: 0.86rem; line-height: 1.3; min-height: 1.3em; margin-top: 6px; color: var(--t3); font-variant-numeric: tabular-nums; }
#yatzy #yz-error { text-align: center; min-height: 0; margin: 2px 0 0; }
#yatzy #yz-error:empty { display: none; }
#yatzy #yz-hint { margin-top: 12px; line-height: 1.45; }

/* The tray: green felt in a gold and dark green frame. The strip along the
   top is the rail for the dice that are kept; a kept die lifts onto it. All
   the sizes follow the width of the tray, so five dice always fit. */
#yatzy #yz-tray { position: relative; width: calc(100% - 18px); max-width: 400px; margin: 16px auto 0; border-radius: 14px; background: radial-gradient(ellipse at 50% 70%, #24684a, #133a28 78%); box-shadow: 0 0 0 2px var(--yz-gold), 0 0 0 8px var(--yz-green), 0 0 0 9px rgba(201, 162, 75, 0.6), 0 12px 24px rgba(0, 0, 0, 0.5); }
#yatzy .yz-rail { position: absolute; left: 0; right: 0; top: 0; height: 50%; border-radius: 14px 14px 0 0; background: rgba(0, 0, 0, 0.24); border-bottom: 1px solid rgba(201, 162, 75, 0.55); display: grid; place-items: center; }
#yatzy .yz-rail-word { font: 700 0.68rem var(--yz-serif); letter-spacing: 0.42em; text-indent: 0.42em; text-transform: uppercase; color: rgba(226, 193, 112, 0.5); }
#yatzy #yz-dice { position: relative; display: grid; grid-template-columns: repeat(5, 1fr); gap: 3%; padding: 26% 4% 5%; }
#yatzy .yz-die { position: relative; display: block; width: 100%; min-height: 0; padding: 0; border: 0; border-radius: 19%; background: linear-gradient(145deg, #fffdf3 0%, #f4ecd6 55%, #e3d7b6 100%); box-shadow: 0 3px 0 #b3a57f, 0 7px 10px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.7); cursor: default; -webkit-tap-highlight-color: transparent; transition: transform 0.24s cubic-bezier(0.3, 1.35, 0.5, 1), box-shadow 0.2s, opacity 0.2s; }
#yatzy .yz-die:disabled { opacity: 1; }
#yatzy .yz-die::before { content: ''; display: block; padding-top: 100%; } /* as tall as it is wide */
#yatzy .yz-face { position: absolute; inset: 15%; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); gap: 6%; }
#yatzy .yz-face i { border-radius: 50%; }
#yatzy .yz-face i.yz-on { background: radial-gradient(circle at 35% 30%, #4a4034, #17130d 70%); box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6); }
#yatzy .yz-die.yz-can { cursor: pointer; }
#yatzy .yz-die.yz-can:active { transform: scale(0.94); }
#yatzy .yz-die.yz-kept { transform: translateY(-138%); box-shadow: 0 0 0 3px var(--yz-gold), 0 0 12px 2px rgba(226, 193, 112, 0.55), 0 5px 8px rgba(0, 0, 0, 0.45); }
#yatzy .yz-die.yz-kept.yz-can:active { transform: translateY(-138%) scale(0.94); }
#yatzy .yz-die.yz-old { opacity: 0.45; }
#yatzy .yz-die.yz-blank { opacity: 0.22; }
#yatzy .yz-die.yz-tumble { animation: yz-tumble 0.56s cubic-bezier(0.3, 0.6, 0.4, 1) both; animation-delay: calc(var(--yz-i, 0) * 35ms); }
#yatzy .yz-die.yz-tumble:nth-child(even) { animation-name: yz-tumble-back; }
@keyframes yz-tumble {
  0% { transform: translateY(-30%) rotate(-200deg) scale(0.9); }
  35% { transform: translateY(6%) rotate(-70deg) scale(1.04); }
  60% { transform: translateY(-12%) rotate(-20deg); }
  82% { transform: translateY(2%) rotate(6deg); }
  100% { transform: translateY(0) rotate(0); }
}
@keyframes yz-tumble-back {
  0% { transform: translateY(-36%) rotate(220deg) scale(0.9); }
  35% { transform: translateY(5%) rotate(80deg) scale(1.04); }
  60% { transform: translateY(-10%) rotate(24deg); }
  82% { transform: translateY(2%) rotate(-7deg); }
  100% { transform: translateY(0) rotate(0); }
}

/* Five the same: the word over the tray, and gold leaf falling. */
#yatzy #yz-cheer { position: absolute; inset: 0; z-index: 3; display: grid; align-content: center; justify-items: center; gap: 2px; border-radius: 14px; background: rgba(9, 28, 19, 0.78); text-align: center; pointer-events: none; }
#yatzy #yz-cheer.yz-pop { animation: yz-cheer 0.45s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes yz-cheer { from { transform: scale(0.6); opacity: 0; } }
#yatzy .yz-cheer-word { font: italic 700 2.7rem var(--yz-serif); letter-spacing: 0.06em; color: var(--yz-gold-lit); text-shadow: 0 2px 0 #6b531c, 0 0 22px rgba(226, 193, 112, 0.6); line-height: 1.05; }
#yatzy .yz-cheer-who { font: 0.9rem var(--yz-serif); color: #f3ead6; }
#yatzy #yz-flakes { position: absolute; inset: 0; z-index: 4; overflow: hidden; border-radius: 14px; pointer-events: none; }
#yatzy .yz-flake { position: absolute; top: -8%; width: 6px; height: 11px; border-radius: 1px; background: linear-gradient(135deg, #f6e3a1, #b98a2c); opacity: 0.95; animation: yz-fall 2.4s linear forwards; }
#yatzy .yz-flake:nth-child(3n) { width: 9px; height: 5px; }
#yatzy .yz-flake:nth-child(4n) { background: linear-gradient(135deg, #fff6d6, #d9b866); }
@keyframes yz-fall {
  from { top: -8%; transform: translateX(0) rotate(0); }
  to { top: 108%; transform: translateX(var(--yz-drift, 0)) rotate(540deg); }
}

/* The roll button, with the rolls left written under the word. */
#yatzy #yz-roll { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; width: calc(100% - 2px); max-width: 418px; min-height: 60px; margin: 18px auto 0; padding: 6px 14px; border-radius: 12px; }
#yatzy #yz-roll.primary { box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
#yatzy #yz-roll.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35); }
#yatzy .yz-roll-word { font: 700 1.3rem var(--yz-serif); letter-spacing: 0.04em; line-height: 1.15; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#yatzy .yz-roll-left { font-size: 0.78rem; font-weight: 600; opacity: 0.85; font-variant-numeric: tabular-nums; }
#yatzy #yz-roll:disabled { opacity: 0.55; }
/* The time left to decide. */
#yatzy #yz-timer { width: calc(100% - 2px); max-width: 418px; height: 6px; margin: 8px auto 0; border-radius: 3px; background: rgba(255, 255, 255, 0.14); overflow: hidden; }
#yatzy #yz-timer.yz-off { visibility: hidden; }
#yatzy #yz-timer-fill { height: 100%; width: 100%; background: var(--accent); border-radius: 3px; transition: width 0.25s linear; }
#yatzy #yz-timer.yz-low #yz-timer-fill { background: #d93025; }
#yatzy #yz-setup > button { min-height: 48px; }

/* The score sheet: parchment in the same frame as the tray, a column a player. */
#yatzy #yz-card { margin: 18px 9px 0; border-radius: 6px; background: var(--yz-paper); box-shadow: 0 0 0 2px var(--yz-gold), 0 0 0 8px var(--yz-green), 0 0 0 9px rgba(201, 162, 75, 0.6), 0 12px 26px rgba(0, 0, 0, 0.5); overflow: hidden; }
#yatzy .yz-sheet { width: 100%; table-layout: fixed; border-collapse: collapse; color: var(--yz-ink); font-family: var(--yz-serif); font-variant-numeric: tabular-nums lining-nums; }
#yatzy .yz-sheet th, #yatzy .yz-sheet td { height: 27px; padding: 0 3px; border-bottom: 1px solid rgba(92, 70, 38, 0.28); border-left: 1px solid rgba(92, 70, 38, 0.28); text-align: center; overflow: hidden; white-space: nowrap; }
#yatzy .yz-sheet tr > :first-child { border-left: 0; }
#yatzy .yz-sheet tbody tr:last-child > * { border-bottom: 0; }
#yatzy .yz-sheet .yz-corner { width: 88px; text-align: left; padding-left: 8px; font: italic 700 0.95rem var(--yz-serif); letter-spacing: 0.04em; color: #7a5a17; background: var(--yz-paper-dark); }
#yatzy .yz-sheet .yz-label { text-align: left; padding-left: 8px; font-weight: 400; font-size: 0.8rem; text-overflow: ellipsis; }
#yatzy .yz-sheet .yz-long { display: none; }
/* A player's column: the name under a bar of their colour. Mine is tinted; a gold line marks whose turn it is. */
#yatzy .yz-sheet .yz-col { height: 30px; padding: 3px 2px 0; border-top: 4px solid var(--yz-col); background: var(--yz-paper-dark); font-size: 0.74rem; font-weight: 700; text-overflow: ellipsis; }
#yatzy .yz-sheet .yz-hdot { display: none; }
#yatzy .yz-sheet .yz-col.yz-turn { box-shadow: inset 0 -3px 0 var(--yz-gold); }
#yatzy .yz-sheet .yz-mine { background: rgba(201, 162, 75, 0.2); }
#yatzy .yz-sheet .yz-col.yz-mine { background: #dcc892; }
#yatzy .yz-sheet .yz-cell { font-size: 0.95rem; }
#yatzy .yz-sheet .yz-ink { font-weight: 700; }
#yatzy .yz-sheet .yz-nought { color: rgba(43, 33, 19, 0.45); font-weight: 400; }
#yatzy .yz-sheet .yz-fresh { animation: yz-fresh 1.7s ease-out; }
@keyframes yz-fresh { 0%, 35% { background: var(--yz-gold); } }
/* The sum of the top six, the bonus and the total. */
#yatzy .yz-sheet .yz-sum > *, #yatzy .yz-sheet .yz-bonus > * { background-color: var(--yz-paper-dark); }
#yatzy .yz-sheet .yz-sum > .yz-mine, #yatzy .yz-sheet .yz-bonus > .yz-mine { background-color: #dcc892; }
#yatzy .yz-sheet .yz-sum > * { border-top: 2px solid rgba(92, 70, 38, 0.55); font-weight: 700; }
#yatzy .yz-sheet .yz-bonus > * { border-bottom: 2px solid rgba(92, 70, 38, 0.55); }
#yatzy .yz-sheet .yz-sum .yz-label, #yatzy .yz-sheet .yz-bonus .yz-label, #yatzy .yz-sheet .yz-total .yz-label { font-weight: 700; font-style: italic; }
#yatzy .yz-sheet .yz-prog { font-size: 0.72rem; color: rgba(43, 33, 19, 0.75); }
#yatzy .yz-sheet .yz-got { font-weight: 700; color: #7a5a17; }
#yatzy .yz-sheet .yz-total > * { height: 32px; background: var(--yz-green); color: var(--yz-gold-lit); font-weight: 700; font-size: 1.05rem; border-color: rgba(201, 162, 75, 0.35); border-top: 2px solid var(--yz-gold); }
#yatzy .yz-sheet .yz-total > .yz-mine { background: #1f5139; color: #f6e3a1; }
/* On my turn: what the dice would score in each free box of mine, in gold. Tap one to write it in. */
#yatzy .yz-sheet .yz-opt { display: block; width: 100%; height: 23px; min-height: 0; padding: 0; border-radius: 6px; border: 1px solid var(--yz-gold); background: var(--yz-green); color: #f0cf7a; font: 700 0.95rem var(--yz-serif); font-variant-numeric: tabular-nums lining-nums; line-height: 1; -webkit-tap-highlight-color: transparent; }
#yatzy .yz-sheet .yz-opt:active { transform: scale(0.94); }
#yatzy .yz-sheet .yz-opt.yz-zero { background: transparent; border-color: rgba(92, 70, 38, 0.3); border-style: dashed; color: rgba(43, 33, 19, 0.42); font-weight: 400; }
#yatzy .yz-sheet .yz-opt.yz-armed { background: #8e2437; border: 1px solid #8e2437; color: #fff; font-weight: 700; }

/* The winner and the final totals, above the sheet. */
#yatzy #yz-result { margin: 16px 0 0; padding: 14px 14px 12px; border-radius: 14px; background: var(--panel); border: 2px solid var(--yz-gold); text-align: center; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.5); }
#yatzy #yz-result.yz-pop { animation: yz-win 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes yz-win { from { transform: scale(0.6); opacity: 0; } }
#yatzy .yz-result-head { font: italic 700 1.45rem var(--yz-serif); color: var(--yz-gold-lit); line-height: 1.2; }
#yatzy .yz-finals { max-width: 320px; margin: 10px auto 0; }
#yatzy .yz-final { display: flex; align-items: baseline; gap: 8px; padding: 4px 10px; border-bottom: 1px solid rgba(201, 162, 75, 0.25); }
#yatzy .yz-final:last-child { border-bottom: 0; }
#yatzy .yz-final-name { flex: 1; min-width: 0; text-align: left; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#yatzy .yz-final-note { font-size: 0.72rem; color: var(--muted); }
#yatzy .yz-final-total { font: 700 1.2rem var(--yz-serif); font-variant-numeric: tabular-nums lining-nums; min-width: 2.2em; text-align: right; }
#yatzy .yz-final-won { border-radius: 8px; background: rgba(201, 162, 75, 0.2); }
#yatzy .yz-final-won .yz-final-total { color: var(--yz-gold-lit); }
#yatzy .yz-result-games { margin-top: 8px; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
#yatzy #yz-again { width: 100%; max-width: 320px; margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  #yatzy .yz-die.yz-tumble, #yatzy .yz-bubble.yz-pop, #yatzy #yz-cheer.yz-pop, #yatzy #yz-result.yz-pop, #yatzy .yz-sheet .yz-fresh, #yatzy .yz-flake { animation: none; }
  #yatzy .yz-flake { display: none; }
  #yatzy .yz-die, #yatzy #yz-timer-fill { transition: none; }
}

/* Room for the full names of the boxes. */
@media (min-width: 520px) {
  #yatzy .yz-sheet .yz-corner { width: 148px; }
  #yatzy .yz-sheet .yz-long { display: inline; }
  #yatzy .yz-sheet .yz-short { display: none; }
  #yatzy .yz-sheet .yz-label { font-size: 0.9rem; }
  #yatzy .yz-sheet th, #yatzy .yz-sheet td { height: 30px; }
  #yatzy .yz-sheet .yz-col { height: 34px; font-size: 0.86rem; }
  #yatzy .yz-sheet .yz-hdot { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 5px; border-radius: 50%; background: var(--yz-col); color: var(--yz-on); font-size: 0.7rem; vertical-align: 1px; }
  #yatzy .yz-sheet .yz-opt { height: 25px; }
  #yatzy .yz-sheet .yz-prog { font-size: 0.8rem; }
}

@media (max-width: 699px) {
  #yatzy { padding-top: 46px; } /* room for the row of round buttons along the top */
  #yatzy #yz-title { padding: 0; }
}
@media (max-width: 380px) {
  #yatzy .yz-player { padding: 3px 5px 3px 4px; gap: 5px; }
  #yatzy .yz-name { font-size: 0.86rem; }
  #yatzy .yz-sheet .yz-corner { width: 84px; }
  #yatzy .yz-sheet .yz-label, #yatzy .yz-sheet .yz-corner { padding-left: 6px; }
  #yatzy .yz-sheet .yz-cols4 .yz-prog { font-size: 0.66rem; letter-spacing: -0.02em; }
}

/* A wide screen: the sheet on the left, the players and the dice beside it.
   The section is made wider than the page's narrow column and centred on it. */
@media (min-width: 900px) {
  #yatzy { --yz-w: min(960px, calc(100vw - 32px)); max-width: none; width: var(--yz-w); margin-left: calc(50% - var(--yz-w) / 2); margin-right: 0; }
  #yatzy #yz-main { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 30px; align-items: start; }
  #yatzy #yz-left, #yatzy #yz-side { display: block; min-width: 0; }
  #yatzy #yz-players { grid-template-columns: 1fr; }
  #yatzy .yz-player { min-height: 54px; }
  #yatzy .yz-player:nth-child(even) .yz-bubble { left: 8px; right: auto; }
  #yatzy .yz-player:nth-child(even) .yz-bubble::after { left: 18px; right: auto; }
  #yatzy #yz-status { margin-top: 14px; font-size: 1.05rem; }
  #yatzy #yz-card { margin-top: 9px; }
  #yatzy #yz-result { margin: 0 0 20px; }
  #yatzy .yz-sheet th, #yatzy .yz-sheet td { height: 32px; }
  #yatzy .yz-sheet .yz-cell { font-size: 1.05rem; }
  #yatzy .yz-sheet .yz-opt { height: 27px; font-size: 1.05rem; }
  #yatzy .yz-sheet .yz-corner { width: 170px; }
}
