  :root {
    --paper: #f7f1e3;
    --paper-deep: #efe4cf;
    --jade: #0b4a3f;
    --jade-2: #0f6250;
    --jade-soft: #e5eee6;
    --ink: #1b302b;
    --ink-soft: #425c54;
    --muted: #6f817a;
    --gold: #c79a54;
    --gold-soft: #ead6ad;
    --cinnabar: #9e352d;
    --line: rgba(23, 70, 60, .2);
    --card: rgba(255, 252, 244, .96);
    --shadow: 0 18px 34px rgba(20, 50, 42, .18);
    --radius: 16px;
  }

  *,
  *::before,
  *::after { box-sizing: border-box; }

  html {
    min-height: 100%;
    background: var(--paper);
  }

  body {
    min-height: 100dvh;
    margin: 0;
    padding: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    color: var(--ink);
    font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
      "PingFang SC", "Microsoft YaHei", sans-serif;
    background:
      linear-gradient(135deg, rgba(11, 74, 63, .08), transparent 36%),
      radial-gradient(560px 260px at 84% 0%, rgba(15, 98, 80, .16), transparent 62%),
      radial-gradient(620px 340px at 12% 100%, rgba(199, 154, 84, .2), transparent 58%),
      var(--paper);
  }

  body::after {
    position: fixed;
    z-index: 0;
    pointer-events: none;
    content: "";
  }

  body::after {
    left: -86px;
    bottom: -46px;
    width: 260px;
    height: 150px;
    border: 1px solid rgba(199, 154, 84, .32);
    border-color: rgba(199, 154, 84, .38) transparent transparent;
    border-radius: 50%;
    transform: rotate(-8deg);
  }

  button,
  input {
    min-width: 0;
    font: inherit;
  }

  button {
    border: 0;
    cursor: pointer;
  }

  h1,
  h2,
  p { margin: 0; }

  .hide { display: none !important; }

  .card {
    position: relative;
    z-index: 1;
    width: min(456px, calc(100vw - 36px));
    max-width: calc(100vw - 36px);
    border: 1px solid rgba(199, 154, 84, .42);
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
    overflow: hidden;
    animation: cardIn .42s cubic-bezier(.16, 1, .3, 1);
  }

  .card::before,
  .card::after {
    position: absolute;
    left: 22px;
    right: 22px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(199, 154, 84, .48), transparent);
    content: "";
    z-index: 2;
  }

  .card::before { top: 13px; }
  .card::after { bottom: 13px; }

  .card-head {
    position: relative;
    isolation: isolate;
    padding: 28px 24px 24px;
    color: var(--paper);
    overflow: hidden;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, .08), transparent 34%),
      linear-gradient(145deg, var(--jade-2), var(--jade) 68%);
  }

  .card-head::before {
    position: absolute;
    inset: 12px;
    border: 1px solid rgba(234, 214, 173, .42);
    border-radius: 12px;
    z-index: 1;
    pointer-events: none;
    content: "";
  }

  .card-head::after {
    position: absolute;
    right: -22px;
    bottom: -56px;
    width: 210px;
    height: 128px;
    border: 1px solid rgba(234, 214, 173, .28);
    border-radius: 50%;
    background:
      radial-gradient(circle at 64% 42%, rgba(234, 214, 173, .13), transparent 46%);
    z-index: 1;
    content: "";
  }

  .badge,
  .card-head h1,
  .card-head p,
  .rule-card,
  .prize-pool {
    position: relative;
    z-index: 2;
    max-width: 100%;
  }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    padding: 4px 12px 4px 4px;
    border: 1px solid rgba(234, 214, 173, .48);
    border-radius: 999px;
    background: rgba(4, 45, 38, .34);
    color: var(--paper);
    font-size: 12px;
    font-weight: 800;
  }

  .badge-logo {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: contain;
    background: rgba(255, 250, 235, .96);
    padding: 3px;
  }

  .festival-art {
    position: absolute;
    right: 10px;
    top: 46px;
    width: 138px;
    max-width: none;
    z-index: 0;
    opacity: .62;
    filter: drop-shadow(0 16px 22px rgba(4, 45, 38, .2));
    pointer-events: none;
  }

  .card-head h1 {
    margin-top: 18px;
    max-width: 100%;
    color: #fff6df;
    font-size: 34px;
    line-height: 1.08;
    font-family: "STKaiti", "KaiTi", "FangSong", ui-serif, serif;
    font-weight: 900;
    letter-spacing: 0;
    text-shadow: 0 2px 0 rgba(32, 26, 16, .16);
  }

  .card-head p {
    margin-top: 8px;
    color: rgba(255, 247, 226, .82);
    font-size: 14px;
    line-height: 1.55;
  }

  .rule-card {
    margin-top: 18px;
    padding: 11px 13px;
    border: 1px solid rgba(234, 214, 173, .62);
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(4, 45, 38, .42), rgba(4, 45, 38, .22));
    color: #fff1c8;
    font-size: 14px;
    font-weight: 900;
    text-align: center;
    white-space: normal;
  }

  .prize-pool {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    margin-top: 12px;
  }

  .prize-pool div {
    min-width: 0;
    padding: 8px 5px;
    border: 1px solid rgba(234, 214, 173, .42);
    border-radius: 10px;
    background: rgba(4, 45, 38, .28);
    text-align: center;
  }

  .prize-pool strong,
  .prize-pool span {
    display: block;
  }

  .prize-pool strong {
    color: #fff3d0;
    font-size: 14px;
    line-height: 1;
  }

  .prize-pool span {
    margin-top: 4px;
    color: rgba(255, 247, 226, .74);
    font-size: 12px;
    font-weight: 800;
  }

  .card-body {
    padding: 22px 24px 26px;
    background:
      linear-gradient(180deg, rgba(255, 255, 255, .36), transparent 34%),
      var(--card);
  }

  .field label {
    display: block;
    margin-bottom: 8px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 850;
  }

  input {
    width: 100%;
    min-height: 50px;
    padding: 13px 15px;
    border: 1px solid rgba(23, 70, 60, .24);
    border-radius: 12px;
    outline: none;
    background: rgba(255, 252, 244, .88);
    color: var(--ink);
    font-size: 14px;
    transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
  }

  input::placeholder { color: #7a8881; }

  input:focus {
    border-color: var(--gold);
    background: #fffdf8;
    box-shadow: 0 0 0 4px rgba(199, 154, 84, .18);
  }

  .hint {
    margin-top: 8px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
  }

  button.primary,
  button.primary-action {
    width: 100%;
    min-height: 50px;
    border-radius: 12px;
    background:
      linear-gradient(180deg, #176b57, var(--jade));
    color: #fff5d9;
    font-size: 15px;
    font-weight: 900;
    box-shadow: inset 0 0 0 1px rgba(234, 214, 173, .28), 0 9px 16px rgba(11, 74, 63, .2);
    transition: transform .16s ease, box-shadow .18s ease, opacity .18s ease, background-color .18s ease;
  }

  button.primary {
    margin-top: 16px;
  }

  button.primary:hover:not(:disabled),
  button.primary-action:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: inset 0 0 0 1px rgba(234, 214, 173, .38), 0 12px 20px rgba(11, 74, 63, .24);
  }

  button.primary:active:not(:disabled),
  button.primary-action:active:not(:disabled) {
    transform: translateY(0);
  }

  button.primary:disabled,
  button.primary-action:disabled {
    cursor: not-allowed;
    opacity: .52;
  }

  button:focus-visible {
    outline: 3px solid rgba(199, 154, 84, .62);
    outline-offset: 3px;
  }

  .draw-console {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 14px;
    align-items: center;
    margin-bottom: 14px;
    padding: 14px;
    border: 1px solid rgba(199, 154, 84, .5);
    border-radius: 14px;
    background:
      linear-gradient(180deg, rgba(255, 253, 247, .94), rgba(244, 235, 217, .86));
    transition: border-color .2s ease, transform .2s ease;
  }

  body.is-drawing .draw-console {
    border-color: var(--cinnabar);
    transform: translateY(-1px);
  }

  .dial {
    position: relative;
    width: 108px;
    aspect-ratio: 1;
    margin: 0 auto;
    display: grid;
    place-items: center;
  }

  .dial-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background:
      conic-gradient(from -18deg, var(--jade), var(--gold), var(--cinnabar), var(--gold), var(--jade));
    -webkit-mask: radial-gradient(circle, transparent 0 55%, #000 56%);
    mask: radial-gradient(circle, transparent 0 55%, #000 56%);
  }

  body.is-drawing .dial-ring {
    animation: dialSpin .82s linear infinite;
  }

  .dial-core {
    position: relative;
    width: 74px;
    height: 74px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(199, 154, 84, .42);
    border-radius: 50%;
    background:
      radial-gradient(circle at 50% 36%, #fffaf0, #f2e2c3);
    color: var(--jade);
    box-shadow: inset 0 0 0 4px rgba(255, 255, 255, .28);
  }

  .dial-face {
    color: var(--jade);
    font-size: 30px;
    font-weight: 950;
    line-height: 1;
  }

  .dial-caption {
    position: absolute;
    bottom: 9px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 850;
  }

  .draw-summary {
    display: grid;
    gap: 10px;
    min-width: 0;
  }

  .activity-name {
    display: grid;
    gap: 3px;
  }

  .activity-name span {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
  }

  .activity-name strong {
    min-width: 0;
    color: var(--jade);
    font-size: 15px;
    overflow-wrap: anywhere;
  }

  .stat-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin: 0;
  }

  .stat-grid div {
    min-width: 0;
    padding: 8px 6px;
    border: 1px solid rgba(23, 70, 60, .12);
    border-radius: 10px;
    background: rgba(255, 252, 244, .88);
  }

  .stat-grid dt {
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
  }

  .stat-grid dd {
    margin: 0;
    color: var(--ink);
    font-size: 18px;
    line-height: 1;
    font-weight: 950;
  }

  .stat-grid .stat-remaining {
    border-color: rgba(158, 53, 45, .22);
    background: #f8e7dc;
  }

  .stat-grid .stat-remaining dd {
    color: var(--cinnabar);
  }

  .draw-state {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    padding-top: 2px;
    color: var(--muted);
    font-size: 12px;
  }

  .draw-state strong {
    color: var(--cinnabar);
  }

  .draw-actions { margin-top: 4px; }

  .result {
    display: none;
    margin-top: 14px;
    padding: 16px;
    border: 1px solid rgba(199, 154, 84, .56);
    border-radius: 14px;
    background:
      linear-gradient(180deg, #fff8e9, #f3e3c6);
    color: var(--ink);
  }

  .result.show {
    display: block;
    animation: pop .3s cubic-bezier(.16, 1, .3, 1);
  }

  .result .face {
    margin: 0 0 8px;
    color: var(--cinnabar);
    font-size: 38px;
    line-height: 1;
    font-weight: 950;
  }

  .result-tip {
    color: var(--ink-soft);
    font-size: 13px;
    line-height: 1.7;
  }

  .result-tip b {
    color: var(--jade);
  }

  .history-pane:empty { display: none; }

  .hist-title {
    margin: 19px 0 8px;
    color: var(--jade);
    font-size: 13px;
    font-weight: 900;
  }

  table.hist {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
  }

  table.hist th,
  table.hist td {
    padding: 9px 4px;
    text-align: left;
    border-bottom: 1px solid rgba(23, 70, 60, .15);
  }

  table.hist th {
    color: var(--muted);
    font-weight: 800;
  }

  table.hist td {
    color: var(--ink-soft);
  }

  table.hist td:first-child {
    color: var(--cinnabar);
    font-weight: 950;
  }

  .status-ok {
    color: var(--jade-2);
    font-weight: 850;
  }

  .status-warn {
    color: var(--cinnabar);
    font-weight: 850;
  }

  .msg {
    min-height: 18px;
    margin-top: 12px;
    color: var(--cinnabar);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.5;
    text-align: center;
  }

  @keyframes cardIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes pop {
    from { opacity: 0; transform: translateY(8px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }

  @keyframes dialSpin {
    to { transform: rotate(1turn); }
  }

  @media (max-width: 390px) {
    body { padding: 10px; }

    .card {
      width: calc(100vw - 20px);
      max-width: calc(100vw - 20px);
    }

    .card-head {
      padding: 24px 18px 20px;
    }

    .card-body {
      padding: 18px 18px 22px;
    }

    .card-head h1 {
      font-size: 30px;
    }

    .festival-art {
      right: 8px;
      top: 48px;
      width: 128px;
      opacity: .6;
    }

    .draw-console {
      grid-template-columns: 1fr;
      gap: 12px;
    }

    .dial {
      width: 104px;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
      animation-duration: .01ms !important;
      animation-iteration-count: 1 !important;
      scroll-behavior: auto !important;
      transition-duration: .01ms !important;
    }
  }
