:root {
  --cream: #fff4dd; --ink: #1d2433; --blue: #4f86ff; --orange: #ff8a35;
  --glass: rgba(18, 24, 38, 0.72); --line: rgba(255, 255, 255, 0.16);
  --font: ui-rounded, "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; background: #6aa0d8; font-family: var(--font); color: var(--cream); user-select: none; -webkit-user-select: none; touch-action: none; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

/* loading */
#loading { position: fixed; inset: 0; z-index: 50; background: linear-gradient(rgba(8, 18, 16, .74), rgba(8, 18, 16, .92)), url("art/key_notitle.jpg?v=1") center / cover #14301f; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; transition: opacity .5s; }
#loading.hidden { display: flex !important; opacity: 0; pointer-events: none; }
#loading .logo { font-size: clamp(44px, 9vw, 96px); font-weight: 900; letter-spacing: 0.04em; color: #ffd36b; text-shadow: 0 5px 0 #8a5a14, 0 12px 28px rgba(0, 0, 0, .45); }
#loading .logo span { color: #fff4dd; }
.ld-bar { width: min(420px, 70vw); height: 12px; border-radius: 9px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.ld-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb347, #ffd36b); border-radius: 9px; transition: width .2s; }
.ld-sub { font-size: 14px; opacity: .8; min-height: 1.3em; text-align: center; padding: 0 20px; }
.ld-brands { position: absolute; bottom: 22px; display: flex; gap: 20px; }
.ld-brand { display: flex; align-items: center; gap: 10px; opacity: .85; }
.ld-brand img { height: 38px; width: 38px; }
.ld-brand small { letter-spacing: .14em; font-size: 11px; }

/* name tags */
#tags { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; padding: 3px 10px 4px; border-radius: 12px; font-size: 13px; font-weight: 800; background: rgba(15, 20, 32, .62); border: 2px solid var(--tc, #fff); color: #fff; white-space: nowrap; will-change: transform; }
.tag.s0 { --tc: #4f86ff; } .tag.s1 { --tc: #ff8a35; }
.tag.on { background: var(--tc); color: #10131c; }
.tag.you::after { content: " (you)"; font-weight: 600; opacity: .8; }
.tag.gone { opacity: .35; }

/* hud */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#score { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; align-items: stretch; gap: 0; background: var(--glass); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(6px); overflow: hidden; box-shadow: 0 8px 24px rgba(0, 0, 0, .28); }
#score .side { display: flex; align-items: center; gap: 10px; padding: 8px 16px; min-width: 190px; border-top: 4px solid var(--c, #fff); }
#score .side.s1 { flex-direction: row; justify-content: flex-end; text-align: right; }
#score .nm b { display: block; font-size: 14px; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#score .pt { font-size: 38px; font-weight: 900; line-height: 1; color: var(--c); min-width: 1.4ch; text-align: center; text-shadow: 0 2px 0 rgba(0, 0, 0, .35); }
#score .pips { display: flex; gap: 4px; }
#score .pips u { width: 9px; height: 9px; border-radius: 3px; background: rgba(255, 255, 255, .15); display: block; }
#score .pips u.on { background: var(--c); }
#mid { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 6px 14px; border-left: 1px solid var(--line); border-right: 1px solid var(--line); min-width: 96px; }
#mid small { font-size: 11px; opacity: .75; letter-spacing: .05em; white-space: nowrap; } #mid b { font-size: 15px; white-space: nowrap; }

#turn { position: absolute; top: calc(max(10px, env(safe-area-inset-top)) + 84px); left: 50%; transform: translateX(-50%); padding: 5px 18px; border-radius: 20px; background: var(--glass); border: 2px solid var(--c, #fff); font-weight: 800; font-size: 15px; letter-spacing: .04em; display: flex; gap: 10px; align-items: center; }
#turn:empty, #turn:has(#turnTxt:empty) { display: none; }
#turn.mine { background: var(--c); color: #10131c; animation: pulse 1.2s ease-in-out infinite; }
#turnClock { font-style: normal; font-variant-numeric: tabular-nums; opacity: .9; }
#turnClock:empty { display: none; }
@keyframes pulse { 50% { transform: translateX(-50%) scale(1.06); } }

#pop { position: absolute; top: 27%; left: 50%; transform: translate(-50%, -50%) scale(.6); font-size: clamp(30px, 4.8vw, 62px); font-weight: 900; letter-spacing: .04em; opacity: 0; white-space: nowrap; text-shadow: 0 4px 0 rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35); }
#pop.show { opacity: 1; transform: translate(-50%, -50%) scale(1); transition: transform .22s cubic-bezier(.2, 1.6, .4, 1), opacity .15s; }
#pop.good { color: #ffe27a; } #pop.ok { color: #fff4dd; } #pop.bad { color: #ff8f7a; }
#sub { position: absolute; top: calc(27% + clamp(22px, 3.4vw, 44px)); left: 50%; transform: translateX(-50%); font-size: 18px; font-weight: 700; text-shadow: 0 2px 8px rgba(0, 0, 0, .6); white-space: nowrap; }

/* the pull-back line: from where the press began down to the pointer */
#pull { position: fixed; display: none; width: 6px; margin-left: -3px; border-radius: 3px; background: linear-gradient(#fff, rgba(255, 226, 122, .85)); box-shadow: 0 0 8px rgba(0, 0, 0, .5); pointer-events: none; z-index: 5; }
#pull::before { content: ""; position: absolute; left: -5px; top: -5px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 0 8px rgba(0, 0, 0, .5); }

/* round summary */
#summary { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: min(440px, 88vw); padding: 18px 22px 16px; border-radius: 22px; background: rgba(14, 20, 34, .84); border: 1px solid var(--line); backdrop-filter: blur(8px); box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
#summary h3 { margin: 0 0 10px; font-size: 13px; letter-spacing: .2em; opacity: .75; text-align: center; }
#summary .r { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 14px; padding: 8px 12px; border-radius: 12px; margin-bottom: 6px; border-left: 6px solid var(--rc); background: rgba(255, 255, 255, .06); }
#summary .r.s0 { --rc: #4f86ff; } #summary .r.s1 { --rc: #ff8a35; }
#summary .r b { font-size: 16px; } #summary .r span { grid-column: 1; font-size: 12px; opacity: .8; } #summary .r em { grid-column: 2; grid-row: 1 / span 2; font-style: normal; font-size: 34px; font-weight: 900; }
#summary p { margin: 10px 0 0; text-align: center; font-weight: 800; font-size: 18px; color: #ffe27a; }

#credits { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; }
#credits > div { background: #151b2a; border: 1px solid var(--line); border-radius: 18px; padding: 22px; max-width: min(520px, 90vw); }
#credits p { line-height: 1.5; font-size: 14px; opacity: .9; } #credits button { font: 700 14px var(--font); padding: 8px 16px; border-radius: 10px; border: 0; cursor: pointer; }

@media (max-width: 700px) {
  #score .side { min-width: 0; padding: 6px 10px; gap: 6px; } #score .nm b { max-width: 84px; font-size: 12px; } #score .pt { font-size: 28px; }
  #mid { min-width: 70px; padding: 4px 8px; }
  
}

/* in-game buttons */
#tools { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; gap: 6px; pointer-events: auto; }
#tools button, #end button, #menu button { font: 700 13px var(--font); color: var(--cream); background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; cursor: pointer; }
#tools button.off { opacity: .5; text-decoration: line-through; }
#tools button:hover, #end button:hover, #menu button:hover { background: rgba(60, 74, 104, .85); }

/* end screen */
#end { position: fixed; inset: 0; z-index: 40; background: rgba(8, 12, 22, .55); display: flex; align-items: center; justify-content: center; }
#end .card { text-align: center; padding: 26px 34px; border-radius: 24px; background: rgba(14, 20, 34, .92); border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(0, 0, 0, .5); max-width: 90vw; }
#end h2 { margin: 0 0 6px; font-size: clamp(30px, 5vw, 52px); font-weight: 900; letter-spacing: .04em; color: #ffe27a; }
#end h2.bad { color: #ff8f7a; }
#end p { margin: 0 0 18px; font-size: 18px; opacity: .9; }
#end .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
#end button, #menu button { font-size: 15px; padding: 10px 20px; }
button.go { background: linear-gradient(#ffc24d, #ff9d2e) !important; color: #2a1800 !important; border-color: transparent !important; }

/* title menu */
#menu { position: fixed; inset: 0; z-index: 45; overflow-y: auto; background: linear-gradient(rgba(8, 18, 16, .84), rgba(8, 18, 16, .95)), url("art/key_notitle.jpg?v=1") center / cover #14301f; display: flex; justify-content: center; align-items: flex-start; touch-action: pan-y; }
#menu .panel { width: min(760px, 94vw); padding: 22px 0 26px; text-align: center; margin: auto; }
#menu .logo { font-size: clamp(40px, 8vw, 80px); font-weight: 900; letter-spacing: .04em; color: #ffd36b; text-shadow: 0 5px 0 #8a5a14, 0 12px 28px rgba(0, 0, 0, .45); line-height: 1; }
#menu .logo span { color: #fff4dd; }
#menu .tag-line { margin: 6px 0 14px; opacity: .85; }
#menu h3 { margin: 12px 0 8px; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; opacity: .75; }
.cast { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
#menu .cast .c { position: relative; overflow: hidden; padding: 6px 4px 8px; border-radius: 16px; background: rgba(14, 26, 22, .72); border: 3px solid transparent; cursor: pointer; font: inherit; color: var(--cream); }
#menu .cast .c img { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; object-position: center top; display: block; pointer-events: none; margin-bottom: 2px; }
#menu .cast .c b { display: block; font-size: 14px; } .cast-info { min-height: 2.6em; margin: 10px auto 0; max-width: 560px; font-size: 14px; line-height: 1.4; opacity: .9; } .cast-info b { color: #ffe27a; margin-right: 4px; }
#menu .cast .c small { display: block; font-size: 11px; opacity: .75; min-height: 2.6em; padding: 0 4px; }
#menu .cast .c.on { border-color: #ffd36b; background: rgba(255, 211, 107, .16); }
.opts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 14px; margin-bottom: 16px; }
.seg { display: flex; gap: 6px; justify-content: center; }
.seg button { flex: 1; padding: 8px 6px !important; font-size: 14px !important; }
#menu .seg button.on { background: #ffd36b !important; color: #2a1800 !important; border-color: transparent !important; }
#menu .go { font-size: 22px !important; padding: 12px 56px !important; border-radius: 16px !important; }
#menu .how { margin: 14px auto 10px; font-size: 13px; line-height: 1.5; opacity: .75; max-width: 520px; }
#menu .brand { display: flex; align-items: center; justify-content: center; gap: 10px; opacity: .85; } #menu .brand img { height: 32px; width: 32px; } #menu .brand small { letter-spacing: .14em; font-size: 11px; }
@media (max-width: 640px) { .cast { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 330px) { .cast { grid-template-columns: repeat(3, 1fr); } }
/* title splash: the key art with a PLAY button */
#landing { position: fixed; inset: 0; z-index: 48; background: #0b1426; display: flex; align-items: center; justify-content: center; }
#landing img { width: 100%; height: 100%; object-fit: contain; }
#landing #landPlay { position: absolute; left: 50%; bottom: 5vh; transform: translateX(-50%); font: 800 clamp(20px, 3vw, 30px) var(--font); padding: 12px 56px; border-radius: 18px; border: 0; cursor: pointer; color: #2a1800; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); animation: landPulse 1.6s ease-in-out infinite; }
@keyframes landPulse { 50% { transform: translateX(-50%) scale(1.05); } }
/* phones and tablets */
.how-touch, .rotate { display: none; }
@media (pointer: coarse) {
  .how-mouse { display: none; } .how-touch { display: inline; }
  #tools { gap: 8px; }
  #tools button { min-height: 42px; min-width: 56px; padding: 8px 14px; font-size: 14px; }
  #end button, #menu button { min-height: 46px; }
  .seg button { min-height: 46px; padding: 10px 6px !important; }
  #menu .cast .c { padding-bottom: 6px; }
  #landing #landPlay { min-height: 54px; }
}
@media (orientation: portrait) and (max-width: 700px) { .rotate { display: block; margin: 4px 0 8px; font-size: 13px; opacity: .8; } }
@media (max-height: 460px) {                      /* a phone on its side */
  #menu .panel { padding-top: 8px; } #menu .logo { font-size: 34px; } #menu .tag-line { margin: 2px 0 6px; font-size: 13px; }
  #menu h3 { margin: 6px 0 4px; } .cast { grid-template-columns: repeat(11, 1fr) !important; gap: 4px; } #menu .cast .c b { font-size: 11px; }
  .cast-info { min-height: 1.4em; margin-top: 4px; font-size: 12px; } .opts { margin-bottom: 8px; } #menu .go { padding: 8px 40px !important; font-size: 18px !important; }
  #menu .how, #menu .brand { display: none; }
  #score .side { padding: 4px 10px; } #score .pt { font-size: 26px; } #turn { top: calc(max(8px, env(safe-area-inset-top)) + 64px); padding: 3px 14px; font-size: 13px; }
  #summary { padding: 10px 14px; transform: translate(-50%, -46%) scale(.86); } #end .card { padding: 14px 22px; }
}
/* upright phone: tighter cards, and the Play button stays on screen while you scroll the roster */
@media (max-width: 700px) and (orientation: portrait) {
  #menu .panel { padding-top: max(14px, env(safe-area-inset-top)); }
  #menu .logo { font-size: 44px; } #menu .tag-line { margin: 2px 0 6px; font-size: 14px; }
  .cast { gap: 6px; } #menu .cast .c { padding: 4px 2px 5px; border-radius: 12px; border-width: 2px; } #menu .cast .c b { font-size: 12px; }
  #btnPlay { position: sticky; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 3; box-shadow: 0 8px 28px rgba(0, 0, 0, .6); }
  .opts { grid-template-columns: 1fr 1fr; gap: 0 10px; }
}
/* small screens: the scoreboard owns the top edge, so the Guide / Sound / Menu buttons go to the bottom-right corner */
@media (max-width: 900px), (max-height: 460px) {
  #tools { top: auto; bottom: max(8px, env(safe-area-inset-bottom)); right: max(8px, env(safe-area-inset-right)); gap: 6px; }
  #tools button { padding: 6px 10px; font-size: 12px; min-height: 36px; min-width: 0; }
}