/* ============ 歪马运动会 · 蓝白运动会风 ============ */
:root{
  --bg:#FBF8EE; --primary:#335CFF; --ink:#182C44; --pale:#DFEAFE;
  --orange:#F28C4B; --teal:#168A87; --white:#fff;
  --line:#c9d4e8; --muted:#5b6b82;
  --font:"Microsoft YaHei","PingFang SC","Noto Sans CJK SC",sans-serif;
  --shadow:0 2px 10px rgba(24,44,68,.08), 0 10px 30px rgba(24,44,68,.07);
  --radius:14px;
  --tap:44px;
}
*{box-sizing:border-box;margin:0;padding:0}
html,body{height:100%}
body{
  font-family:var(--font); background:var(--bg); color:var(--ink);
  -webkit-font-smoothing:antialiased; overflow-x:hidden;
}
button{font-family:inherit;cursor:pointer;touch-action:manipulation}
img{display:block;max-width:100%}
b,strong{font-weight:700}
.mono,.hud-stats b{font-variant-numeric:tabular-nums; font-family:Consolas,"Microsoft YaHei",monospace}

/* ---------- 顶栏 ---------- */
.topbar{
  position:sticky;top:0;z-index:50;display:flex;align-items:center;justify-content:space-between;
  padding:14px 32px;background:rgba(251,248,238,.92);backdrop-filter:blur(6px);
  border-bottom:2px solid var(--pale);
}
.brand{display:flex;align-items:center;gap:12px}
.brand-mark{width:44px;height:27px;transform:rotate(-4deg)}
.brand-name{font-size:22px;font-weight:800;letter-spacing:1px;display:block}
.brand-sub{font-size:11px;letter-spacing:3px;color:var(--muted);display:block}
.topbar-actions{display:flex;gap:10px}
.icon-btn{
  width:44px;height:44px;border-radius:12px;border:2px solid var(--pale);background:var(--white);
  color:var(--ink);font-size:18px;font-weight:700;display:grid;place-items:center;
}
.icon-btn:hover{border-color:var(--primary);color:var(--primary)}
.icon-btn.off{opacity:.45}

/* ---------- 按钮 ---------- */
.btn{
  border:none;border-radius:14px;font-weight:700;letter-spacing:1px;
  display:inline-flex;align-items:center;justify-content:center;gap:8px;
  transition:transform .06s ease, box-shadow .12s ease;min-height:var(--tap);
}
.btn:active{transform:translateY(1px)}
.btn.primary{background:var(--primary);color:#fff;box-shadow:0 4px 0 #2243c4}
.btn.primary:hover{background:#4a6cff}
.btn.secondary{background:var(--white);color:var(--primary);border:2px solid var(--primary)}
.btn.big{font-size:24px;padding:0 40px;height:88px;border-radius:18px}
.btn.big.secondary{height:80px;font-size:22px}
.btn.small{font-size:14px;padding:0 14px;height:44px;border-radius:10px;min-width:44px}
.btn.cta{width:100%;height:82px;font-size:24px}
.link-btn{background:none;border:none;color:var(--muted);text-decoration:underline;font-size:14px;min-height:44px;padding:4px 10px}
.link-btn:hover{color:var(--primary)}
.btn:focus-visible,.icon-btn:focus-visible,.tool:focus-visible{outline:3px solid var(--orange);outline-offset:2px}

.screen[hidden]{display:none!important}
#app{min-height:100vh;display:flex;flex-direction:column}
#main{flex:1}

/* ================= 首页（桌面） ================= */
#screen-home{padding:0 32px 24px}
.home-hero{display:flex;gap:24px;align-items:flex-start;position:relative;z-index:2}
.home-copy{flex:0 0 620px;padding-top:110px}
.home-headline{font-size:96px;line-height:1.12;font-weight:800;letter-spacing:2px}
.home-sub{font-size:24px;color:var(--muted);margin-top:18px}
.home-note{font-size:16px;color:var(--muted);margin-top:14px}
.home-lastchip{
  display:inline-block;margin-top:12px;padding:6px 14px;border-radius:999px;
  background:var(--pale);color:var(--ink);font-size:14px;
}
.home-hero-art{
  flex:1;height:470px;display:flex;align-items:center;justify-content:center;
  margin-top:6px;transform:rotate(2deg);
}
.home-hero-art img{height:430px;width:auto;max-width:100%;filter:drop-shadow(0 12px 18px rgba(24,44,68,.12))}
.home-track-strip{position:relative;margin-top:-105px;z-index:1}
.home-track-strip img.track-desktop{width:100%;height:340px;object-fit:cover;object-position:bottom}
.home-track-strip img.track-mobile{display:none}
.strip-horse{position:absolute;width:120px;filter:drop-shadow(0 4px 6px rgba(24,44,68,.15))}
.strip-horse.s1{left:22%;top:30%;transform:rotate(-3deg)}
.strip-horse.s2{left:47%;top:47%;width:104px;transform:rotate(2deg)}
.strip-horse.s3{left:66%;top:23%;width:96px;transform:rotate(-2deg)}
.strip-flag{position:absolute;right:6%;top:12%;width:54px}
.home-cta-row{display:flex;gap:20px;margin-top:10px;align-items:center}
.home-cta-row .btn.primary{min-width:306px}
.home-cta-row .btn.secondary{min-width:218px}
.home-steps{
  list-style:none;display:flex;gap:24px;justify-content:flex-start;
  margin-top:18px;padding:18px 24px;background:var(--white);border:2px solid var(--pale);
  border-radius:var(--radius);max-width:900px;
}
.home-steps li{font-size:20px;font-weight:700;display:flex;gap:10px;align-items:baseline}
.home-steps b{color:var(--primary);font-size:15px;letter-spacing:1px}
.home-steps li + li{border-left:2px dashed var(--line);padding-left:24px}

/* ================= 画室（桌面） ================= */
#screen-studio{padding:0 32px 24px}
.studio-body{display:flex;gap:36px;align-items:stretch}
.studio-left{flex:1;min-width:0;display:flex;flex-direction:column}
.studio-head{display:flex;align-items:flex-end;gap:24px;padding:58px 8px 18px}
.studio-head .back{margin-bottom:14px}
.studio-title h1{font-size:60px;font-weight:800;letter-spacing:1px}
.studio-title p{font-size:24px;color:var(--muted);margin-top:8px}
.canvas-wrap{
  position:relative;width:100%;height:600px;background:var(--white);
  border:3px solid var(--ink);border-radius:18px;overflow:hidden;box-shadow:var(--shadow);
}
#draw-canvas{width:100%;height:100%;display:block;touch-action:none;cursor:crosshair}
.canvas-tip{
  position:absolute;right:18px;bottom:12px;font-size:14px;color:#b9c4d8;pointer-events:none;
}
.toolbar{
  display:flex;align-items:center;gap:14px;margin-top:14px;padding:10px 14px;
  background:var(--white);border:2px solid var(--pale);border-radius:14px;
}
.tool{
  width:48px;height:48px;border-radius:10px;border:2px solid var(--line);background:var(--white);
  font-size:19px;color:var(--ink);display:grid;place-items:center;
}
.tool:hover{border-color:var(--primary);color:var(--primary)}
.tool.active{background:var(--primary);color:#fff;border-color:var(--primary)}
.width-group{display:flex;gap:8px;align-items:center;border-left:2px dashed var(--line);border-right:2px dashed var(--line);padding:0 14px;height:48px}
.width-btn[data-w="6"] span,
.width-btn .dot{display:inline-block;border-radius:50%;background:currentColor}
.width-btn[data-w="6"]{font-size:8px}
.width-btn[data-w="12"]{font-size:13px}
.width-btn[data-w="22"]{font-size:20px}
.toolbar .spacer{flex:1}

.entry-form{
  flex:0 0 440px;background:var(--pale);border-radius:18px;padding:26px;
  display:flex;flex-direction:column;gap:18px;box-shadow:var(--shadow);padding-bottom:96px;
}
.entry-form .cta{margin-top:auto}
.entry-form label{font-size:18px;font-weight:700;display:block;margin-bottom:8px}
.name-row{display:flex;gap:10px}
#name-input{
  flex:1;min-width:0;height:48px;border-radius:10px;border:2px solid #b9c9ec;background:var(--white);
  font-size:18px;padding:0 12px;font-family:inherit;color:var(--ink);
}
#name-input:focus-visible{outline:3px solid var(--orange);outline-offset:1px}
.field-hint{font-size:13px;color:var(--muted);margin-top:6px}
.preview-box{background:var(--white);border-radius:14px;padding:12px;border:2px dashed #b9c9ec}
.preview-label{font-size:13px;color:var(--muted);margin-bottom:6px}
#preview-canvas{width:100%;height:130px;display:block}
.save-status{font-size:13px;color:var(--teal);min-height:18px}

/* ================= 比赛（桌面） ================= */
#screen-race{padding:6px 32px 24px;display:flex;flex-direction:column;min-height:calc(100vh - 76px)}
.race-hud{
  display:flex;align-items:center;justify-content:space-between;gap:20px;
  background:var(--white);border:2px solid var(--pale);border-radius:14px;padding:12px 20px;margin-top:38px;
}
.hud-title{font-size:26px;font-weight:800}
.hud-round{font-size:16px;color:var(--muted);margin-left:12px}
.hud-stats{display:flex;gap:30px;flex-wrap:wrap}
.hud-stats .stat{font-size:16px;color:var(--muted);display:flex;align-items:baseline;gap:6px}
.hud-stats .stat label{font-size:14px}
.hud-stats .stat b{font-size:28px;color:var(--ink);font-weight:800}
.hud-stats .stat.seed b{font-size:14px;color:var(--muted);font-weight:400}

.arena{display:flex;gap:0;background:var(--white);border:2px solid var(--pale);border-radius:16px;overflow:hidden;box-shadow:var(--shadow);height:clamp(320px,40vh,420px);margin-top:48px}
.lane-labels{flex:0 0 240px;display:flex;flex-direction:column;border-right:2px solid var(--pale);background:var(--bg)}
.lane-label{
  flex:1;display:flex;flex-direction:column;justify-content:center;padding:4px 16px;
  border-bottom:1px solid #eee6d2;min-width:0;
}
.lane-label:last-child{border-bottom:none}
.lane-label .nm{font-size:19px;font-weight:700;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.lane-label .tag{
  display:inline-block;font-size:12px;padding:1px 8px;border-radius:999px;margin-top:3px;width:max-content;
  background:var(--pale);color:var(--ink);
}
.lane-label.player .tag{background:var(--primary);color:#fff}
.lane-label.ghost .tag{background:#fff;color:var(--muted);border:1px dashed var(--muted)}
.lane-label.ghost .nm{color:var(--muted)}
.arena-track{flex:1;position:relative;min-width:0}
#arena-canvas{display:block;width:100%;height:100%}

.race-controls{display:flex;gap:20px;align-items:stretch;margin-top:12px}
.judge-line{
  display:flex;align-items:center;justify-content:center;gap:24px;
  background:var(--white);border:2px solid var(--pale);border-radius:14px;padding:6px 20px;
  min-height:56px;margin-top:26px;
}
.judge-label{font-size:30px;font-weight:800;color:var(--muted)}
.judge-label.perfect{color:var(--orange)}
.judge-label.good{color:var(--primary)}
.judge-label.miss{color:#c0392b}
.judge-combo{font-size:16px;font-weight:700;color:var(--ink)}
.rhythm-wrap{flex:1;display:flex;flex-direction:column;gap:8px;justify-content:center;min-width:0}
.rhythm-bar{
  position:relative;height:78px;background:var(--white);border:2px solid var(--ink);border-radius:12px;overflow:hidden;
}
.rhythm-bar .zone{position:absolute;top:0;bottom:0}
.rhythm-bar .zone.good{left:38%;width:24%;background:var(--pale)}
.rhythm-bar .zone.perfect{left:45%;width:10%;background:var(--orange)}
.rhythm-bar .pointer{
  position:absolute;top:0;bottom:0;width:6px;background:var(--white);border:2px solid var(--ink);
  border-radius:3px;left:0;box-shadow:0 0 6px rgba(24,44,68,.35);z-index:2;
}
.rhythm-hint{font-size:13px;color:var(--muted);text-align:center}
.zone-legend{padding:0 6px;border-radius:4px;font-size:12px}
.zone-legend.lg-good{background:var(--pale)}
.zone-legend.lg-perfect{background:var(--orange);color:#fff}
.tap-btn{
  flex:0 0 340px;flex-direction:column;gap:2px;height:150px;font-size:34px;border-radius:18px;
}
.tap-sub{font-size:14px;font-weight:400;opacity:.85;letter-spacing:0}
.race-controls .link-btn{align-self:flex-end;min-height:36px;font-size:14px;padding:2px 8px}

/* ---------- 覆盖层 ---------- */
.overlay{
  position:fixed;inset:0;z-index:80;display:flex;align-items:center;justify-content:center;
  background:rgba(24,44,68,.38);padding:20px;
}
.overlay[hidden]{display:none}
.overlay.global{z-index:120}
.panel{
  background:var(--bg);border-radius:20px;border:3px solid var(--ink);box-shadow:var(--shadow);
  padding:28px;max-width:640px;width:100%;max-height:calc(100vh - 60px);overflow:auto;
}
.panel h2{font-size:30px;font-weight:800;margin-bottom:8px}
.panel-sub{font-size:15px;color:var(--muted);margin-bottom:18px}
.panel-actions{display:flex;gap:12px;flex-wrap:wrap;margin-top:20px}
.panel-actions .btn{flex:1;min-width:140px;height:56px;font-size:18px}
#ov-countdown{background:rgba(251,248,238,.72);flex-direction:column;gap:14px;z-index:70}
.countdown-num{font-size:190px;font-weight:800;color:var(--primary);line-height:1;text-shadow:0 10px 0 var(--pale)}
.countdown-sub{font-size:20px;color:var(--ink);background:var(--white);padding:10px 22px;border-radius:999px;border:2px solid var(--pale)}

/* 结算 */
.results-panel{max-width:860px}
.results-body{display:flex;gap:26px;margin-top:12px}
.results-art{flex:0 0 300px;display:flex;flex-direction:column;gap:10px}
#results-canvas{width:300px;height:210px;background:var(--white);border:2px solid var(--pale);border-radius:14px}
.results-name{font-size:20px;font-weight:700;text-align:center}
.results-info{flex:1;min-width:0}
.results-rank{font-size:22px;font-weight:800;color:var(--primary)}
.results-time{font-size:44px;font-weight:800;margin:6px 0 14px}
.results-stats{list-style:none;display:flex;gap:14px;flex-wrap:wrap}
.results-stats li{
  background:var(--white);border:2px solid var(--pale);border-radius:12px;padding:10px 16px;
  display:flex;flex-direction:column;align-items:center;min-width:88px;
}
.results-stats b{font-size:26px}
.results-stats span{font-size:13px;color:var(--muted)}
.results-diff{margin-top:14px;font-size:17px;font-weight:700;color:var(--teal)}
.rank-table{margin-top:14px;border-collapse:collapse;font-size:15px;width:100%}
.rank-table td,.rank-table th{padding:6px 10px;border-bottom:1px solid #eee6d2;text-align:left}
.rank-table th{color:var(--muted);font-weight:400;font-size:13px}
.rank-table .you td{color:var(--primary);font-weight:800}
.rank-table .ghost td{color:var(--muted)}

/* 分享 */
.share-panel{max-width:560px}
.share-preview{margin:12px 0}
.share-preview canvas,.share-preview img{width:100%;max-width:320px;border-radius:14px;border:2px solid var(--pale);display:block;margin:0 auto}
.share-text{font-size:15px;background:var(--white);border:2px dashed var(--line);border-radius:10px;padding:12px}
.share-tip{font-size:13px;color:var(--muted);margin-top:10px;text-align:center}

/* 通用弹窗 */
.modal-panel h2{font-size:24px}
.modal-panel p{font-size:15px;line-height:1.7}
.modal-panel ul{margin:10px 0 0 20px;font-size:15px;line-height:1.8}

/* Toast */
#toast-root{position:fixed;left:50%;bottom:28px;transform:translateX(-50%);z-index:200;display:flex;flex-direction:column;gap:8px;align-items:center;pointer-events:none}
.toast{
  background:var(--ink);color:#fff;font-size:15px;padding:12px 22px;border-radius:12px;
  box-shadow:var(--shadow);animation:toast-in .2s ease;max-width:min(90vw,480px);text-align:center;
}
.toast.warn{background:#a4432f}
@keyframes toast-in{from{opacity:0;transform:translateY(10px)}to{opacity:1;transform:none}}

/* 减少动态效果 */
@media (pointer: coarse){
  .kbd-only{display:none}
}
@media (prefers-reduced-motion: reduce){
  .btn{transition:none}
  .countdown-num{animation:none}
}

/* ==================== 移动端 ==================== */
@media (max-width: 860px){
  :root{--radius:12px}
  .topbar{padding:10px 16px}
  .brand-mark{width:34px;height:21px}
  .brand-name{font-size:17px}
  .brand-sub{font-size:9px;letter-spacing:2px}
  .icon-btn{width:40px;height:40px;font-size:15px;border-radius:10px}
  body{font-size:15px}

  /* 首页 */
  #screen-home{padding:0 16px calc(16px + env(safe-area-inset-bottom,0px));display:flex;flex-direction:column}
  .home-hero{order:1;flex-direction:column;gap:0}
  .home-copy{padding-top:54px;flex:none}
  .home-headline{font-size:48px;line-height:1.15}
  .home-sub{font-size:15px;margin-top:10px}
  .home-note{font-size:13px;margin-top:8px}
  .home-lastchip{font-size:13px}
  .home-hero-art{display:none}
  .home-track-strip{order:2;margin-top:4px}
  .home-track-strip img.track-desktop{display:none}
  .home-track-strip img.track-mobile{display:block;width:100%;height:252px;object-fit:cover;object-position:bottom}
  .home-cta-row{order:3;flex-direction:column;gap:10px;margin-top:16px}
  .home-cta-row .btn{width:100%}
  .btn.big{height:64px;font-size:20px;border-radius:14px}
  .btn.big.secondary{height:56px;font-size:18px}
  .home-cta-row .btn.primary{min-width:0}
  .home-cta-row .btn.secondary{min-width:0}
  .strip-horse{width:64px}
  .strip-horse.s1{left:18%;top:34%}
  .strip-horse.s2{left:46%;top:52%;width:56px}
  .strip-horse.s3{left:68%;top:26%;width:52px}
  .strip-flag{width:34px;right:5%;top:14%}
  .home-steps{order:4;gap:10px;padding:12px 14px;margin-top:14px}
  .home-steps li{font-size:13px}
  .home-steps b{font-size:11px}
  .home-steps li + li{padding-left:10px}

  /* 画室 */
  #screen-studio{padding:0 16px calc(24px + env(safe-area-inset-bottom,0px))}
  .studio-head{flex-direction:row-reverse;align-items:center;justify-content:space-between;gap:12px;padding:6px 0 10px}
  .studio-head .back{margin:0;flex:none}
  .studio-title h1{font-size:23px;white-space:nowrap}
  .studio-title p{font-size:14px;margin-top:3px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .studio-body{flex-direction:column;gap:14px}
  .studio-left{width:100%}
  .canvas-wrap{height:308px;border-width:2px;border-radius:14px}
  .toolbar{gap:8px;padding:6px 8px;margin-top:8px}
  .tool{width:44px;height:44px;font-size:16px;border-radius:9px}
  .width-btn{width:36px;padding:0}
  .width-group{padding:0 8px;gap:6px;height:44px}
  .toolbar .spacer{display:none}
  .entry-form{flex:none;width:100%;padding:10px;gap:10px}
  .entry-form .cta{margin-top:auto}
  .entry-form label{font-size:15px;margin-bottom:6px}
  #name-input{height:44px;font-size:16px}
  #preview-canvas{height:84px}
  .save-status{font-size:12px;min-height:14px}
  .btn.cta{height:58px;font-size:20px}

  /* 比赛 */
  #screen-race{padding:4px 12px calc(12px + env(safe-area-inset-bottom,0px));gap:10px;min-height:100dvh}
  .race-hud{margin-top:10px;padding:12px 14px}
  .arena{height:268px;margin-top:0}
  .race-hud{flex-direction:column;align-items:stretch;gap:8px;padding:10px 14px;border-radius:12px}
  .hud-title{font-size:18px}
  .hud-round{font-size:12px;margin-left:6px}
  .hud-stats{gap:12px;justify-content:space-between}
  .hud-stats .stat{gap:4px}
  .hud-stats .stat b{font-size:19px}
  .hud-stats .stat.seed{display:none}
  .lane-labels{flex:0 0 78px;border-right-width:1.5px}
  .lane-label{padding:2px 8px}
  .lane-label .nm{font-size:12px;white-space:normal;line-height:1.2;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
  .lane-label .tag{font-size:10px;padding:0 6px;margin-top:2px}
  .race-controls{flex-direction:column;gap:10px;position:relative;margin-top:10px}
  .judge-line{
    justify-content:space-between;padding:8px 16px;border-radius:12px;min-height:52px;margin-top:12px;
  }
  .judge-label{font-size:22px}
  .judge-combo{font-size:14px}
  .rhythm-bar{height:38px}
  .rhythm-hint{font-size:12px}
  .tap-btn{flex:none;width:100%;height:72px;font-size:24px;border-radius:16px}
  .race-controls .link-btn{position:static;order:9;align-self:center;min-height:40px;font-size:13px}
  #tap-sub{display:none}

  /* 结算 */
  .panel{padding:18px;border-width:2px}
  .panel h2{font-size:22px}
  .results-body{flex-direction:column;gap:14px}
  .results-art{flex:none;flex-direction:row;align-items:center;gap:14px}
  #results-canvas{width:140px;height:100px;flex:none}
  .results-name{font-size:17px;text-align:left}
  .results-time{font-size:34px;margin:2px 0 10px}
  .panel-actions .btn{min-width:110px;height:50px;font-size:16px}
  .countdown-num{font-size:110px}
  .countdown-sub{font-size:14px;padding:8px 14px;text-align:center}
}
@media (min-width: 861px) and (max-width: 1100px){
  .home-copy{padding-top:60px}
  .home-headline{font-size:64px}
  .studio-body{gap:20px}
  .entry-form{flex-basis:340px}
  .canvas-wrap{height:560px}
}
