@layer base, layout, components, responsive;

@layer base {
  :root {
    color-scheme: light;
    --cream: #fbf3e4;
    --paper: #fffbf2;
    --ink: #29221c;
    --muted: #625748;
    --rule: #dcd1bf;
    --line: #a69680;
    --yellow: #f5d472;
    --sage: #bfd797;
    --red: #f0a896;
    --english: #3c774c;
    --edge: 2px solid var(--ink);
    --stamp: 5px 6px 0 var(--ink);
    --radius: 20px;
    --ease-out: cubic-bezier(.23,1,.32,1);
    font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
    font-variant-numeric: tabular-nums;
    background: var(--cream);
    color: var(--ink);
  }
  *, *::before, *::after { box-sizing: border-box; }
  body { margin: 0; }
  h1, h2, h3, p, ol, ul { margin: 0; }
  button, input { font: inherit; color: inherit; }
  button { cursor: pointer; }
  button:disabled { cursor: wait; }
  [hidden] { display: none !important; }
  :focus-visible { outline: 2px solid #83541d; outline-offset: 4px; }
  svg { flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
  .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; white-space: nowrap; clip-path: inset(50%); }
}

@layer layout {
  .wrap { width: min(1080px, calc(100% - 104px)); margin: 0 auto; padding: 71px 0 max(80px, env(safe-area-inset-bottom)); }
  .panel { border: var(--edge); border-radius: var(--radius); background: var(--paper); box-shadow: var(--stamp); }
  .hero { min-height: 315px; padding: 35px 48px; display: flex; align-items: center; justify-content: space-between; gap: 26px; background: #f9e7ae; overflow: hidden; }
  .hero-copy { position: relative; z-index: 1; }
  .date-strip { display: flex; align-items: center; gap: 7px; color: #54452b; font-size: 14px; letter-spacing: .06em; margin-bottom: 20px; font-weight: 700; }
  h1 { font-size: clamp(42px, 5.25vw, 74px); font-weight: 900; letter-spacing: -.034em; line-height: .99; }
  h1 span { display: flex; align-items: baseline; gap: .20em; margin-top: 11px; font-size: .61em; letter-spacing: -.045em; }
  h1 strong { font-family: "Arial Black", "Arial", sans-serif; font-size: 1.14em; font-weight: 900; color: #874332; letter-spacing: -.07em; }
  .hero-art { width: min(39%, 364px); height: auto; flex: none; margin-right: 10px; }
  .challenge-progress { display: flex; flex-wrap: wrap; align-items: center; gap: 9px 15px; margin-top: 25px; }
  .challenge-day { font-size: 13px; font-weight: 800; white-space: nowrap; color: #514129; }
  .personal { margin-top: 57px; }
  .statistics { margin-top: clamp(98px, 11vw, 155px); }
  .section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
  h2 { font-weight: 900; font-size: clamp(24px, 3vw, 35px); letter-spacing: -.045em; line-height: 1.12; }
  .personal-panel { overflow: hidden; }
  .login-line, .identity { min-height: 85px; display: flex; gap: 12px; align-items: center; padding: 18px 24px 10px; }
  .login-line { justify-content: center; }
  .identity { font-size: 16px; font-weight: 800; gap: 9px; }
  #person-name { overflow-wrap: anywhere; }
  .student-no { color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
  .personal-count { color: #3b5a3b; font-size: 15px; font-weight: 800; white-space: nowrap; }
  .scroll-cue { display: none; color: var(--muted); }
  .rank-head .scroll-cue { margin-left: auto; align-self: center; }
  .days-scroll, .leaderboard-scroll { overflow-x: auto; overscroll-behavior-inline: contain; scrollbar-width: thin; scrollbar-color: #a29782 transparent; outline-offset: -3px; }
  .panel-foot { display: flex; justify-content: flex-end; margin: 0 24px; border-top: 1px solid var(--rule); padding: 14px 0 17px; }
  .stats-band { display: grid; grid-template-columns: 1.15fr 1fr; margin-bottom: 29px; background: #f5eadd; border: 1px solid #c6b79f; border-radius: 15px; }
  .stat { padding: 20px 23px 21px; min-width: 0; }
  .stat + .stat { border-left: 1px solid #c6b79f; }
  .stat-label { font-size: 14px; color: var(--muted); font-weight: 700; }
  .stat-number { display: flex; align-items: baseline; gap: 8px; margin-top: 5px; }
  .stat-number strong { font-size: clamp(29px, 5vw, 50px); font-family: "Arial", sans-serif; font-weight: 900; letter-spacing: -.06em; line-height: 1; }
  .stat-number span { font-size: 13px; font-weight: 700; color: var(--muted); }
  .rank-card { overflow: hidden; }
  .rank-head { display: flex; gap: 13px; align-items: baseline; padding: 23px 24px 16px; }
  .rank-head h3 { font-weight: 900; font-size: 22px; letter-spacing: -.035em; }
  .rank-label { color: var(--muted); font-size: 13px; white-space: nowrap; font-weight: 750; }
  .rank-empty { min-height: 110px; padding: 18px 24px 32px; gap: 12px; display: grid; place-content: center; text-align: center; color: var(--muted); font-size: 14px; border-top: 1px solid var(--rule); }
}

@layer components {
  .button { min-height: 44px; border: var(--edge); border-radius: 11px; background: var(--paper); display: inline-flex; align-items: center; justify-content: center; gap: 11px; font-weight: 800; padding: 8px 17px; line-height: 1.25; transition: transform 150ms var(--ease-out); }
  .button:active:not(:disabled) { transform: translate(2px, 2px) scale(.98); }
  .primary { background: var(--yellow); box-shadow: 3px 4px 0 var(--ink); }
  .primary:active:not(:disabled) { box-shadow: 1px 2px 0 var(--ink); }
  .secondary { border-width: 1px; background: var(--paper); min-height: 38px; font-size: 14px; }
  .quiet { color: var(--muted); font-size: 14px; }
  .track { display: flex; gap: 3px; width: 151px; }
  .track span { position: relative; flex: 1; height: 6px; border-radius: 2px; background: #e2cb91; }
  .track span.on { background: var(--ink); }
  .track span.current { background: #914b38; }
  .average-track { width: min(100%, 151px); margin-top: 13px; }
  .average-track span { height: 5px; background: #ddceba; }
  .average-track span.on { background: var(--english); }
  .personal-days { list-style: none; display: grid; grid-template-columns: repeat(14, minmax(39px, 1fr)); gap: 11px; min-width: max-content; padding: 5px 24px 23px; }
  .personal-days li { min-width: 0; }
  .day-tile, .key { position: relative; display: grid; place-items: center; border: 1.5px solid var(--ink); background: var(--paper); border-radius: 9px; }
  .day-tile { height: 46px; min-width: 39px; font: 800 16px/1 "Arial", sans-serif; }
  .is-pass { background: var(--sage); }
  .is-fail { background: var(--red); }
  .is-blank { border-style: dashed; border-color: var(--line); color: #6e5e4a; background: #f8f2e7; }
  .is-english::after, .key-english::after { position: absolute; content: ''; inset: -5px; border: 2px solid var(--english); border-radius: inherit; pointer-events: none; }
  .key-english::after { inset: -4px; }
  .key-english { border-color: #a1ae92; background: #f3f4e8; }
  .legend { display: flex; flex-wrap: wrap; list-style: none; gap: 10px 19px; padding: 0; color: var(--muted); font-size: 13px; font-weight: 650; }
  .legend li { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
  .key { width: 15px; height: 15px; border-radius: 4px; }
  .login-dialog { width: min(405px, calc(100% - 36px)); max-height: calc(100% - 36px); padding: 24px; outline: none; opacity: 0; transform: translateY(7px) scale(.98); transition: opacity 180ms var(--ease-out), transform 180ms var(--ease-out), overlay 180ms allow-discrete, display 180ms allow-discrete; }
  .login-dialog[open] { opacity: 1; transform: none; }
  .login-dialog::backdrop { background: rgb(41 34 28 / 39%); opacity: 0; transition: opacity 180ms var(--ease-out), overlay 180ms allow-discrete, display 180ms allow-discrete; }
  .login-dialog[open]::backdrop { opacity: 1; }
  @starting-style {
    .login-dialog[open] { opacity: 0; transform: translateY(7px) scale(.98); }
    .login-dialog[open]::backdrop { opacity: 0; }
  }
  body:has(.login-dialog[open]) { overflow: hidden; }
  .dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 19px; }
  .dialog-head h2 { font-size: 26px; }
  .dialogue-close { border: 1px solid var(--line); width: 44px; padding: 0; }
  form { display: grid; gap: 9px; }
  form label { font-size: 14px; font-weight: 800; }
  form input { padding: 9px 12px; min-height: 46px; border: 1.5px solid #8b7b67; background: var(--paper); border-radius: 9px; width: 100%; font-size: 16px; }
  form input + label { margin-top: 4px; }
  .form-error { color: #913e33; font-size: 14px; font-weight: 700; }
  .submit { margin-top: 7px; justify-self: stretch; }
  .ranks { border-spacing: 0; width: 100%; min-width: 604px; text-align: center; table-layout: fixed; padding: 0 13px 13px; }
  .ranks th, .ranks td { border-top: 1px solid var(--rule); height: 43px; padding: 4px; }
  .ranks thead th { font-size: 12px; color: var(--muted); }
  .ranks thead th:first-child { width: 58px; }
  .ranks thead th:last-child { width: 58px; }
  .ranks tbody th { font: 800 15px/1 "Arial", sans-serif; }
  .ranks .day-tile { min-width: 0; width: min(75%, 28px); height: 22px; margin: auto; border-radius: 5px; }
  .ranks .is-english::after { inset: -4px; border-width: 1.5px; }
  .rank-passed { font-size: 14px; font-weight: 800; }
  @media (hover: hover) and (pointer: fine) {
    .primary:hover:not(:disabled) { background: #fadf87; }
    .secondary:hover, .dialogue-close:hover { background: #f4ebdb; }
  }
}

@layer responsive {
  @media (max-width: 855px) {
    .panel-foot { justify-content: space-between; align-items: center; }
    .panel-foot .scroll-cue { display: block; }
  }
  @media (max-width: 662px) {
    .rank-card:has(.leaderboard-scroll:not([hidden])) .rank-head .scroll-cue { display: block; }
  }
  @media (max-width: 780px) {
    .wrap { width: calc(100% - 48px); padding-top: 40px; }
    .hero { padding-inline: 30px; min-height: 273px; }
    .hero-art { margin-right: 0; width: 40%; }
  }
  @media (max-width: 540px) {
    :root { --radius: 16px; --stamp: 3px 4px 0 var(--ink); }
    .wrap { width: calc(100% - 38px); padding-top: 27px; }
    .hero { position: relative; min-height: 237px; padding: 22px 16px; }
    .hero-art { position: absolute; inset: auto 2px 9px auto; width: 43%; }
    .hero-copy { width: 100%; }
    h1 { font-size: clamp(34px, 9.4vw, 48px); }
    h1 span { margin-top: 8px; }
    .date-strip { font-size: 12px; margin-bottom: 18px; }
    .challenge-progress { gap: 7px; flex-direction: column; align-items: flex-start; margin-top: 19px; }
    .challenge-day { font-size: 12px; }
    .challenge-progress .track { width: 110px; gap: 2px; }
    .personal { margin-top: 43px; }
    .statistics { margin-top: 100px; }
    .section-head { margin-bottom: 12px; }
    .personal-days { padding-inline: 15px; gap: 10px; }
    .login-line, .identity { min-height: 77px; padding: 15px 15px 10px; }
    .panel-foot { margin-inline: 15px; padding-bottom: 14px; gap: 9px; }
    .legend { gap: 9px 12px; font-size: 11px; }
    .legend li { gap: 5px; }
    .key { width: 13px; height: 13px; }
    .stat { padding: 15px 13px; }
    .rank-head { padding-inline: 15px; }
    .ranks { padding-inline: 5px; }
  }
  @media (prefers-reduced-motion: reduce) {
    .button, .login-dialog, .login-dialog::backdrop { transition: none; }
    .button:active:not(:disabled) { transform: none; }
  }
}
