﻿:root {
      --bg0: #0a0a0d;
      --bg1: #12121a;
      --surface: #1a1a24;
      --border: rgba(255, 255, 255, 0.08);
      --text: #f4f2ff;
      --muted: #8b87a0;
      --accent: #7c6cff;
      --accent2: #ff6cab;
      --glow: rgba(124, 108, 255, 0.45);
      --success: #5fe3b3;
      --charge: #ffd066;
      --radius: 20px;
      --safe-bottom: env(safe-area-inset-bottom, 0px);
      --tap-size: min(68vw, 268px);
    }

    * { box-sizing: border-box; }
    html, body { height: 100%; margin: 0; }

    body {
      font-family: "DM Sans", system-ui, sans-serif;
      background: radial-gradient(120% 80% at 50% -20%, #1f1a35 0%, var(--bg0) 45%), var(--bg0);
      color: var(--text);
      min-height: 100dvh;
      overflow-x: hidden;
      -webkit-tap-highlight-color: transparent;
      user-select: none;
    }

    .app {
      max-width: 480px;
      margin: 0 auto;
      min-height: 100dvh;
      display: flex;
      flex-direction: column;
      padding: 10px 16px calc(14px + var(--safe-bottom));
      gap: 8px;
    }

    header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 10px;
    }

    .brand {
      display: flex;
      align-items: center;
      gap: 0.55rem;
      font-weight: 700;
      font-size: 1.05rem;
      letter-spacing: -0.02em;
      min-width: 0;
    }

    .back-home {
      flex: 0 0 auto;
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--muted);
      text-decoration: none;
      white-space: nowrap;
      padding-right: 0.55rem;
      margin-right: 0.15rem;
      border-right: 1px solid var(--border);
    }

    .back-home:hover {
      color: var(--text);
      text-decoration: underline;
    }

    .stats {
      display: flex;
      gap: 8px;
      flex-wrap: wrap;
      justify-content: flex-end;
    }

    .pill {
      font-size: 0.72rem;
      font-weight: 600;
      padding: 6px 10px;
      border-radius: 999px;
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--muted);
    }

    .pill strong { color: var(--text); }

    .settings-view .btn-settings {
      margin-top: 22px;
    }

    .preset-row {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin-bottom: 18px;
    }

    .preset-chip {
      font-family: inherit;
      font-size: 0.72rem;
      font-weight: 600;
      padding: 8px 12px;
      border-radius: 999px;
      border: 1px solid var(--border);
      background: var(--bg1);
      color: var(--text);
      cursor: pointer;
      touch-action: manipulation;
    }

    .preset-chip:active {
      filter: brightness(1.12);
    }

    .draw-mode-field {
      border: none;
      margin: 0 0 20px;
      padding: 0;
    }

    .draw-mode-field .draw-mode-legend {
      margin-bottom: 10px;
    }

    .draw-mode-options {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .draw-mode-option {
      display: flex;
      align-items: flex-start;
      gap: 10px;
      font-size: 0.82rem;
      font-weight: 500;
      color: var(--text);
      cursor: pointer;
    }

    .draw-mode-option input {
      margin-top: 3px;
      flex-shrink: 0;
    }

    .draw-mode-hint {
      display: block;
      font-size: 0.68rem;
      font-weight: 500;
      color: var(--muted);
      margin-top: 4px;
      line-height: 1.35;
    }

    .main-view[hidden],
    .settings-view[hidden],
    .history-view[hidden] {
      display: none !important;
    }

    .history-view {
      min-height: 100dvh;
      padding: 14px 18px calc(20px + var(--safe-bottom));
      max-width: 480px;
      margin: 0 auto;
      background: radial-gradient(120% 80% at 50% -20%, #1f1a35 0%, var(--bg0) 45%), var(--bg0);
    }

    .settings-view {
      min-height: 100dvh;
      padding: 14px 18px calc(20px + var(--safe-bottom));
      max-width: 480px;
      margin: 0 auto;
      background: radial-gradient(120% 80% at 50% -20%, #1f1a35 0%, var(--bg0) 45%), var(--bg0);
    }

    .settings-header {
      display: flex;
      align-items: center;
      gap: 12px;
      margin-bottom: 20px;
    }

    .settings-title {
      font-size: 1.15rem;
      font-weight: 700;
      margin: 0;
      letter-spacing: -0.02em;
    }

    .settings-lead {
      margin: 0 0 18px;
      text-align: left;
      max-width: none;
    }

    .btn-back,
    .btn-settings {
      font-family: inherit;
      font-size: 0.85rem;
      font-weight: 600;
      cursor: pointer;
      touch-action: manipulation;
      border-radius: 12px;
      border: 1px solid var(--border);
      background: var(--surface);
      color: var(--text);
      padding: 10px 14px;
    }

    .btn-back {
      flex-shrink: 0;
    }

    .btn-settings {
      width: 100%;
      padding: 12px 16px;
    }

    .btn-settings-row {
      display: flex;
      width: 100%;
      justify-content: space-between;
      align-items: center;
      gap: 12px;
    }

    .btn-settings-meta {
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--muted);
    }

    .btn-back:active,
    .btn-settings:active {
      filter: brightness(1.08);
    }

    .settings-section-label {
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--muted);
      margin-bottom: 10px;
      display: flex;
      justify-content: space-between;
      align-items: baseline;
      gap: 8px;
    }

    .pool-input {
      width: 100%;
      min-height: 120px;
      resize: vertical;
      border-radius: 12px;
      border: 1px solid var(--border);
      background: var(--bg1);
      color: var(--text);
      font-family: "JetBrains Mono", monospace;
      font-size: 0.85rem;
      padding: 10px 12px;
      user-select: text;
      -webkit-user-select: text;
    }

    .pool-input:focus {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }

    .pool-help {
      margin-top: 8px;
      font-size: 0.68rem;
      color: var(--muted);
      line-height: 1.45;
    }

    .charge-wrap {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 11px 14px;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .charge-top {
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 10px;
    }

    .charge-top-right {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      gap: 8px;
      flex: 1;
      min-width: 0;
    }

    .charge-label {
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--muted);
      flex-shrink: 0;
    }

    .charge-hint {
      font-size: 0.72rem;
      color: var(--muted);
      opacity: 0.85;
      flex-shrink: 0;
    }

    .charge-bar-outer {
      height: 12px;
      border-radius: 999px;
      background: rgba(0, 0, 0, 0.35);
      overflow: hidden;
      border: 1px solid var(--border);
      position: relative;
    }

    .charge-bar-inner {
      height: 100%;
      width: 0%;
      border-radius: inherit;
      background: linear-gradient(90deg, var(--accent), var(--charge));
      box-shadow: 0 0 24px var(--glow);
      transition: width 0.35s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .charge-bar-inner.pulse {
      animation: barPulse 0.6s ease;
    }

    .charge-coins {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: flex-end;
      gap: 2px 3px;
      min-height: 2px;
      flex: 1;
      min-width: 0;
    }

    .charge-coin-dot {
      width: 2px;
      height: 2px;
      border-radius: 50%;
      flex-shrink: 0;
      background: radial-gradient(circle at 35% 30%, #fff6c8, #e8c040 45%, #a67c00);
      box-shadow: 0 0 1px rgba(0, 0, 0, 0.4);
    }

    .charge-coins-more {
      font-size: 0.55rem;
      font-weight: 700;
      color: var(--charge);
      line-height: 1;
      margin-left: 2px;
    }

    @keyframes barPulse {
      0%, 100% { filter: brightness(1); }
      50% { filter: brightness(1.25); }
    }

    .stage {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 104px;
      position: relative;
    }

    .result {
      font-family: "JetBrains Mono", monospace;
      font-weight: 700;
      font-size: clamp(3rem, 14vw, 4.5rem);
      letter-spacing: -0.04em;
      text-align: center;
      line-height: 1;
      text-shadow: 0 0 40px var(--glow);
      transition: transform 0.15s ease, opacity 0.15s ease, font-size 0.15s ease;
    }

    .result.short {
      font-size: clamp(4.35rem, 22vw, 7rem);
      letter-spacing: -0.06em;
    }

    .result.spin { opacity: 0.65; transform: scale(0.96); }

    .whisper {
      margin-top: 6px;
      font-size: 0.95rem;
      font-weight: 600;
      font-style: italic;
      color: var(--accent2);
      min-height: 1.25em;
      text-align: center;
      opacity: 0;
      transition: opacity 0.25s ease;
    }

    .whisper.show { opacity: 1; }

    .history {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      justify-content: center;
      max-width: 100%;
      margin-top: 6px;
      min-height: 30px;
    }

    .history .chip-action {
      cursor: pointer;
      touch-action: manipulation;
    }

    .history .chip-action:hover {
      filter: brightness(1.08);
    }

    .history .chip-action:active {
      transform: scale(0.97);
    }

    .history .chip-action:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }

    .history-full-body {
      margin-top: 4px;
    }

    .history-full-list {
      list-style: none;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .history-full-item {
      display: flex;
      align-items: flex-start;
      gap: 12px;
      padding: 10px 14px;
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: 12px;
    }

    .history-full-n {
      font-size: 0.72rem;
      color: var(--muted);
      min-width: 2em;
      flex-shrink: 0;
      font-family: "JetBrains Mono", monospace;
    }

    .history-full-body {
      flex: 1;
      min-width: 0;
      display: flex;
      flex-wrap: wrap;
      align-items: baseline;
      justify-content: space-between;
      gap: 6px 12px;
    }

    .history-full-val {
      font-size: 0.95rem;
      font-weight: 500;
      color: var(--text);
      word-break: break-word;
      font-family: "JetBrains Mono", monospace;
    }

    .history-full-time {
      font-size: 0.68rem;
      font-weight: 600;
      color: var(--muted);
      font-family: inherit;
      flex-shrink: 0;
      white-space: nowrap;
    }

    .history-actions {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      margin-bottom: 16px;
    }

    .btn-history-action {
      font-family: inherit;
      font-size: 0.82rem;
      font-weight: 600;
      cursor: pointer;
      touch-action: manipulation;
      border-radius: 12px;
      border: 1px solid var(--border);
      background: var(--surface);
      color: var(--text);
      padding: 10px 14px;
      flex: 1;
      min-width: 132px;
    }

    .btn-history-action:active:not(:disabled) {
      filter: brightness(1.08);
    }

    .btn-history-action:disabled {
      opacity: 0.45;
      cursor: default;
    }

    .chip {
      font-family: "JetBrains Mono", monospace;
      font-size: 0.8rem;
      padding: 6px 12px;
      border-radius: 999px;
      background: rgba(124, 108, 255, 0.15);
      border: 1px solid rgba(124, 108, 255, 0.35);
      color: var(--text);
    }

    .chip.ellipsis {
      background: rgba(255, 255, 255, 0.04);
      border-color: var(--border);
      color: var(--muted);
      letter-spacing: 0.12em;
    }

    .draw-zone {
      margin-top: auto;
      padding-top: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 10px;
    }

    .btn-draw {
      width: var(--tap-size);
      height: var(--tap-size);
      max-height: 36vh;
      border-radius: 50%;
      border: none;
      cursor: pointer;
      font-family: inherit;
      font-weight: 700;
      font-size: clamp(1rem, 4.2vw, 1.25rem);
      letter-spacing: 0.02em;
      color: #0c0b12;
      background: radial-gradient(circle at 30% 25%, #fff 0%, #e8e4ff 18%, #b8adff 45%, var(--accent) 100%);
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.35) inset,
        0 12px 40px rgba(124, 108, 255, 0.5),
        0 4px 0 rgba(80, 65, 180, 0.9);
      transition: transform 0.12s ease, box-shadow 0.2s ease, filter 0.2s ease;
      position: relative;
      touch-action: manipulation;
    }

    .btn-draw:active:not(:disabled) {
      transform: scale(0.97) translateY(2px);
      box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.25) inset,
        0 6px 24px rgba(124, 108, 255, 0.4),
        0 2px 0 rgba(80, 65, 180, 0.85);
    }

    .btn-draw:disabled {
      cursor: default;
      filter: grayscale(0.15) brightness(0.92);
      box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
    }

    .btn-draw.breathe:not(:disabled) {
      animation: breathe 3.2s ease-in-out infinite;
    }

    @keyframes breathe {
      0%, 100% { transform: scale(1); filter: brightness(1); }
      50% { transform: scale(1.035); filter: brightness(1.06); }
    }

    .btn-draw.mini-nudge {
      animation: nudge 0.7s ease;
    }

    @keyframes nudge {
      0%, 100% { transform: rotate(0deg); }
      25% { transform: rotate(-2deg) scale(1.02); }
      75% { transform: rotate(2deg) scale(1.02); }
    }

    @media (prefers-reduced-motion: reduce) {
      .btn-draw.breathe { animation: none; }
      .charge-bar-inner { transition: none; }
    }

    .subtle {
      font-size: 0.75rem;
      color: var(--muted);
      text-align: center;
      max-width: 280px;
      line-height: 1.35;
    }

    #confetti-canvas {
      position: fixed;
      inset: 0;
      pointer-events: none;
      z-index: 50;
    }

    .toast {
      position: fixed;
      left: 50%;
      bottom: calc(120px + var(--safe-bottom));
      transform: translateX(-50%) translateY(20px);
      background: var(--surface);
      border: 1px solid var(--border);
      color: var(--text);
      padding: 12px 18px;
      border-radius: 14px;
      font-weight: 600;
      font-size: 0.9rem;
      opacity: 0;
      pointer-events: none;
      z-index: 60;
      box-shadow: 0 16px 50px rgba(0, 0, 0, 0.45);
      transition: opacity 0.25s ease, transform 0.25s ease;
    }

    .toast.show {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }

    .pool-alert {
      width: 100%;
      max-width: 100%;
      margin-bottom: 10px;
      padding: 12px 14px;
      border-radius: var(--radius);
      border: 1px solid var(--border);
      background: var(--surface);
    }

    .pool-alert[hidden] {
      display: none !important;
    }

    .pool-alert-title {
      margin: 0 0 6px;
      font-size: 0.88rem;
      font-weight: 600;
      color: var(--text);
      letter-spacing: -0.02em;
    }

    .pool-alert-text {
      margin: 0 0 12px;
      font-size: 0.78rem;
      line-height: 1.4;
      color: var(--muted);
    }

    .pool-alert .pool-alert-action {
      margin-top: 0;
      font-weight: 600;
    }

    .pool-settings-needs-attention {
      border-color: rgba(124, 108, 255, 0.45) !important;
    }
