:root {
  --ink: #fffaf2;
  --purple: #24102f;
  --purple-2: #12091c;
  --orange: #ff9d28;
  --red: #f04444;
  --yellow: #ffd75a;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body {
  background: #12091c;
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game {
  position: relative;
  width: 100%; height: 100%; min-height: 480px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 115%, rgba(245, 119, 38, .35), transparent 32%),
    radial-gradient(circle at 15% 25%, rgba(151, 74, 178, .22), transparent 28%),
    linear-gradient(160deg, #2b1635 0%, #170c24 48%, #0d0815 100%);
  isolation: isolate;
}

#game::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: -1;
  opacity: .15;
  background-image: url("data:image/svg+xml,%3Csvg width='90' height='90' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.45'/%3E%3C/svg%3E");
}

.ambient { position: absolute; width: 32vw; height: 32vw; border-radius: 50%; filter: blur(80px); opacity: .16; z-index: -1; }
.ambient-a { background: #e74369; left: -12vw; bottom: 3vh; }
.ambient-b { background: #ffa92f; right: -12vw; top: 15vh; }

canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }

.hud {
  position: absolute; z-index: 10; top: 0; left: 0; right: 0;
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: max(16px, env(safe-area-inset-top)) clamp(16px, 4vw, 54px) 8px;
  pointer-events: none;
}
.brand { display: flex; gap: 10px; align-items: center; text-shadow: 0 2px 12px #000; }
.brand-logo { width: 50px; height: 46px; padding: 0; border-radius: 0; object-fit: contain; background: transparent; box-shadow: none; }
.brand b { display: block; font-size: clamp(18px, 2.3vw, 28px); letter-spacing: .08em; }
.brand small { display: block; font-size: 9px; letter-spacing: .34em; color: #f0c87b; margin-top: 1px; }
.hud-pill {
  min-width: 108px; height: 62px; padding: 8px 16px; border-radius: 18px;
  display: flex; gap: 11px; align-items: center; justify-content: center;
  background: rgba(15, 7, 24, .62); border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 12px 30px rgba(0,0,0,.22); backdrop-filter: blur(12px);
}
.hud-pill > span { font-size: 12px; color: #d9c9dc; }
.hud-pill strong { font-size: 28px; line-height: 1; }
.hud-pill em { font-style: normal; }
.hud-pill small { font-size: 11px; margin-left: 3px; color: #d9c9dc; }
.score-pill strong { color: var(--yellow); }
.score-pill { min-width: 142px; height: 76px; }
.score-pill strong { font-size: 56px; letter-spacing: -.04em; }
.timer-pill.urgent { border-color: rgba(255,85,75,.8); animation: pulse .75s infinite alternate; }
.timer-pill.urgent strong { color: #ff6c60; }
@keyframes pulse { to { transform: scale(1.04); box-shadow: 0 0 24px rgba(255,76,64,.3); } }

.score-key {
  position: absolute; z-index: 9; top: 91px; left: 50%; transform: translateX(-50%);
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 15px;
  padding: 8px 13px; border-radius: 99px; white-space: nowrap;
  font-size: 11px; font-weight: 700; letter-spacing: .02em; color: rgba(255,255,255,.8);
  background: rgba(20,9,28,.42); border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(8px); pointer-events: none;
}
.score-key span { display: inline-flex; align-items: center; gap: 5px; }
.score-key .danger { color: #ff9389; }
.dot { width: 7px; height: 7px; border-radius: 50%; box-shadow: 0 0 8px currentColor; }
.gold { background: #f7c052; color: #f7c052; }.green { background: #91ce4b; color: #91ce4b; }
.pink { background: #ff8fbc; color: #ff8fbc; }.red { background: #ff5349; color: #ff5349; }

.panel {
  position: absolute; z-index: 20; left: 50%; top: 50%; transform: translate(-50%, -48%);
  width: min(680px, calc(100% - 32px)); padding: clamp(25px, 5vw, 48px);
  text-align: center; border-radius: 36px;
  background: linear-gradient(145deg, rgba(55,28,67,.93), rgba(20,10,29,.95));
  border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 35px 90px rgba(0,0,0,.56), inset 0 1px 0 rgba(255,255,255,.09);
  backdrop-filter: blur(22px); transition: opacity .35s, transform .35s, visibility .35s;
}
.panel.hidden { opacity: 0; visibility: hidden; transform: translate(-50%, -45%) scale(.96); pointer-events: none; }
.eyebrow { color: #f7bf61; font-size: 12px; font-weight: 900; letter-spacing: .36em; margin-bottom: 10px; }
h1 { margin: 0; font-size: clamp(46px, 9vw, 78px); line-height: .98; letter-spacing: .02em; text-shadow: 0 8px 25px rgba(0,0,0,.28); }
h1 span { color: #ff9d38; }
.lead { color: #ded0df; font-size: clamp(14px, 2vw, 17px); line-height: 1.8; margin: 18px 0 24px; }
.how-to { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: center; gap: 9px; margin-bottom: 26px; }
.step { min-width: 0; }
.step > span { display: grid; place-items: center; width: 27px; height: 27px; margin: 0 auto 7px; border-radius: 50%; background: #f5a135; color: #28132d; font-weight: 900; }
.step b { display: block; font-size: 13px; }
.step small { display: block; font-size: 10px; color: #a99aac; margin-top: 3px; }
.arrow { color: #826e88; }
.primary {
  appearance: none; border: 0; min-width: 218px; height: 58px; padding: 0 22px 0 27px;
  display: inline-flex; justify-content: center; align-items: center; gap: 18px;
  border-radius: 18px; color: #29142e; font: 900 17px inherit; letter-spacing: .08em;
  background: linear-gradient(135deg, #ffd85a, #ff9e2f 70%); cursor: pointer;
  box-shadow: 0 12px 30px rgba(255,152,42,.27), inset 0 1px 0 rgba(255,255,255,.65);
  transition: transform .18s, filter .18s; touch-action: manipulation;
}
.primary:hover { transform: translateY(-2px) scale(1.015); filter: brightness(1.06); }
.primary:active { transform: translateY(1px) scale(.98); }
.primary:disabled { cursor: wait; opacity: .68; filter: grayscale(.25); transform: none; }
.primary i { font-style: normal; font-size: 22px; }
.hint { margin: 13px 0 0; font-size: 10px; color: #8e7b93; letter-spacing: .08em; }

.result-panel { width: min(520px, calc(100% - 32px)); max-height: min(92vh, 760px); overflow-y: auto; scrollbar-width: thin; }
.grade {
  width: 110px; height: 110px; margin: 0 auto 10px; display: grid; place-items: center;
  border: 5px solid #ffd75a; border-radius: 50%; color: #ffd75a; font-size: 64px; font-weight: 900;
  transform: rotate(-7deg); text-shadow: 0 4px 12px rgba(0,0,0,.4); box-shadow: 0 0 28px rgba(255,215,90,.14);
}
.result-panel h2 { font-size: 30px; margin: 4px 0; }.result-panel h2 span { font-size: 58px; color: #fff; }
.result-copy { color: #d9c9dc; margin: 6px 0 12px; }
.best { display: inline-flex; gap: 8px; padding: 7px 15px; border-radius: 99px; background: rgba(255,255,255,.07); font-size: 12px; color: #bbaebe; }
.best strong { color: #ffc854; }
.score-submit { margin: 16px 0 12px; }
.score-submit label { display: block; margin-bottom: 7px; color: #f8dc9a; font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.name-row { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.name-row input {
  min-width: 0; height: 44px; padding: 0 14px; border-radius: 12px; outline: none;
  border: 1px solid rgba(255,255,255,.16); background: rgba(8,4,13,.48); color: #fff;
  font: 700 14px inherit; transition: border-color .2s, box-shadow .2s;
}
.name-row input:focus { border-color: #ffc756; box-shadow: 0 0 0 3px rgba(255,199,86,.13); }
.name-row button {
  height: 44px; padding: 0 18px; border: 0; border-radius: 12px; cursor: pointer;
  background: linear-gradient(135deg,#ffd95d,#ff9e35); color: #29142e; font: 900 13px inherit;
}
.name-row button:disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.5); }
.submit-status { min-height: 18px; margin: 5px 2px 0; font-size: 11px; color: #b9a9bd; }
.submit-status.error { color: #ff8178; }.submit-status.success { color: #8ee09a; }
.leaderboard { margin: 10px 0 16px; padding: 12px 14px; border-radius: 17px; background: rgba(8,4,13,.38); border: 1px solid rgba(255,255,255,.08); text-align: left; }
.leaderboard-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 7px; }
.leaderboard-head h3 { margin: 0; font-size: 14px; letter-spacing: .08em; }.leaderboard-head > span { color: #f7bd58; font: 900 9px inherit; letter-spacing: .16em; }
.leaderboard ol { list-style: none; padding: 0; margin: 0; max-height: 174px; overflow-y: auto; }
.leaderboard li { display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 7px; min-height: 31px; padding: 4px 3px; border-bottom: 1px solid rgba(255,255,255,.055); font-size: 12px; }
.leaderboard li:last-child { border-bottom: 0; }.leaderboard .rank { color: #a991ad; font-weight: 900; }.leaderboard .player { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }.leaderboard .points { color: #ffd65b; font-weight: 1000; }
.leaderboard .top-1 .rank { color: #ffd34e; }.leaderboard .top-2 .rank { color: #d8d9df; }.leaderboard .top-3 .rank { color: #dd996c; }
.leaderboard li.loading,.leaderboard li.empty { display: block; padding: 13px 3px; color: #8f8094; text-align: center; }
.grade-table { display: grid; grid-template-columns: repeat(4,1fr); gap: 6px; margin: 20px 0; }
.grade-table span { padding: 8px 3px; border-radius: 11px; background: rgba(255,255,255,.055); font-size: 10px; color: #a999ad; }
.grade-table b { display: block; font-size: 20px; color: #f4e8f4; }

.combo {
  position: absolute; z-index: 8; left: 50%; top: 20%; transform: translate(-50%,-50%) scale(.5) rotate(-6deg);
  font-size: clamp(34px, 7vw, 66px); font-weight: 1000; font-style: italic; color: #ffe36c;
  text-shadow: 0 3px #e64e32, 0 0 18px rgba(255,194,60,.8); opacity: 0; pointer-events: none;
}
.combo.show { animation: combo .55s ease-out; }
@keyframes combo { 0%{opacity:0;transform:translate(-50%,-50%) scale(.35) rotate(-10deg)} 35%{opacity:1;transform:translate(-50%,-50%) scale(1.1) rotate(-4deg)} 100%{opacity:0;transform:translate(-50%,-70%) scale(.95) rotate(-2deg)} }
.rage-banner {
  position: absolute; z-index: 12; left: 50%; top: 23%;
  display: grid; justify-items: center; opacity: 0; visibility: hidden; pointer-events: none;
  transform: translate(-50%,-50%) scale(.5) rotate(-5deg);
  transition: opacity .2s, visibility .2s;
  filter: drop-shadow(0 7px 15px rgba(0,0,0,.55));
}
.rage-banner small { padding: 4px 13px; border-radius: 99px; background: #fff4c4; color: #821c20; font-size: 11px; font-weight: 1000; letter-spacing: .22em; }
.rage-banner strong { font-size: clamp(44px, 9vw, 86px); line-height: .95; color: #ffdf58; font-weight: 1000; font-style: italic; text-shadow: 0 4px 0 #e13632, 0 0 24px rgba(255,65,43,.9); white-space: nowrap; }
.rage-banner span { font-size: 11px; font-weight: 1000; letter-spacing: .48em; color: #fff; }
.rage-banner.show { animation: rage-in 1.15s ease-out forwards; visibility: visible; }
@keyframes rage-in {
  0% { opacity: 0; transform: translate(-50%,-50%) scale(.25) rotate(-10deg); }
  22% { opacity: 1; transform: translate(-50%,-50%) scale(1.16) rotate(-3deg); }
  45%, 78% { opacity: 1; transform: translate(-50%,-50%) scale(1) rotate(-3deg); }
  100% { opacity: 0; transform: translate(-50%,-70%) scale(.92) rotate(-1deg); visibility: hidden; }
}
#game.rage { animation: rage-bg .55s infinite alternate; }
#game.rage::after {
  content: ""; position: absolute; inset: 0; z-index: 7; pointer-events: none;
  box-shadow: inset 0 0 90px rgba(255,45,35,.22); animation: rage-vignette .35s infinite alternate;
}
@keyframes rage-bg { to { background-color: #250817; } }
@keyframes rage-vignette { to { box-shadow: inset 0 0 135px rgba(255,67,33,.34); } }
.rotate-note { display: none; }

.admin-trigger {
  position: absolute; z-index: 30; left: max(9px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom));
  width: 30px; height: 30px; padding: 0; border: 0; border-radius: 50%; cursor: default;
  display: grid; place-items: center; font-size: 18px; line-height: 1; opacity: .38;
  background: rgba(20,9,28,.45); filter: saturate(.8); transition: opacity .2s, transform .2s;
  touch-action: manipulation;
}
.admin-trigger:focus-visible { opacity: 1; outline: 2px solid rgba(255,173,60,.55); }
.admin-trigger[hidden] { display: none !important; }
.admin-modal {
  position: absolute; z-index: 70; inset: 0; display: grid; place-items: center; padding: 18px;
  background: rgba(7,3,11,.74); backdrop-filter: blur(10px); transition: opacity .2s, visibility .2s;
}
.admin-modal.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.admin-card {
  width: min(360px,100%); padding: 25px; border-radius: 24px; text-align: center;
  background: linear-gradient(145deg,#3a1b43,#170b20); border: 1px solid rgba(255,255,255,.16);
  box-shadow: 0 28px 70px rgba(0,0,0,.58);
}
.admin-icon { font-size: 34px; }.admin-card h2 { margin: 4px 0 7px; font-size: 22px; }
.admin-card > p:not(.admin-status) { margin: 0 0 17px; color: #bbaabd; font-size: 12px; }
.admin-card label { display: block; margin-bottom: 6px; text-align: left; color: #f5d596; font-size: 11px; font-weight: 900; }
.admin-card input {
  width: 100%; height: 44px; padding: 0 13px; border-radius: 12px; outline: none;
  border: 1px solid rgba(255,255,255,.16); background: rgba(4,2,7,.5); color: #fff; font: 700 14px inherit;
}
.admin-card input:focus { border-color: #f7a63f; box-shadow: 0 0 0 3px rgba(247,166,63,.13); }
.admin-status { min-height: 18px; margin: 6px 0; font-size: 11px; color: #ff8a80; }
.admin-status.success { color: #8ee09a; }
.admin-actions { display: grid; grid-template-columns: 1fr 1.3fr; gap: 8px; margin-top: 8px; }
.admin-actions button { height: 42px; border: 0; border-radius: 12px; cursor: pointer; color: #fff; background: rgba(255,255,255,.1); font: 900 12px inherit; }
.admin-actions .danger-button { background: linear-gradient(135deg,#ff795e,#d9323d); }
.admin-actions button:disabled { opacity: .5; cursor: wait; }

@media (max-width: 650px) {
  .hud { grid-template-columns: 1fr auto auto; gap: 6px; padding-left: 12px; padding-right: 12px; }
  .brand-logo { width: 42px; height: 38px; border-radius: 0; }.brand { gap: 7px; }.brand b { font-size: 15px; }.brand small { font-size: 6px; letter-spacing: .18em; }
  .hud-pill { height: 52px; min-width: 68px; padding: 6px 9px; gap: 5px; border-radius: 14px; }.hud-pill > span { display: none; }.hud-pill strong { font-size: 23px; }
  .score-pill { height: 62px; min-width: 94px; }.score-pill strong { font-size: 42px; }
  .score-key { top: 76px; max-width: calc(100% - 20px); white-space: normal; padding: 6px 11px; gap: 4px 10px; font-size: 9px; }
  .panel { border-radius: 27px; padding: 26px 18px; }.lead { margin: 14px 0 20px; }
  .how-to { gap: 4px; }.step small { display: none; }.step b { font-size: 11px; }.arrow { font-size: 11px; }
  .primary { height: 54px; min-width: 200px; }
}

@media (max-height: 620px) {
  .panel { padding-top: 20px; padding-bottom: 20px; }.lead { margin: 10px 0 13px; line-height: 1.5; }.how-to { margin-bottom: 14px; }
  .hint { display: none; } h1 { font-size: 42px; }.grade { width: 76px; height: 76px; font-size: 44px; }.result-panel h2 span { font-size: 42px; }.grade-table { margin: 10px 0; }
}

@media (orientation: landscape) and (max-height: 430px) and (pointer: coarse) {
  .rotate-note { display: grid; position: absolute; inset: 0; z-index: 50; place-items: center; padding: 30px; text-align: center; background: #160c20; font-weight: 900; }
}

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