  *, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

  :root {
    --bg-deep: #191127;
    --bg-mid: #180f26;
    --bg-card: #23133a;
    --gold: #883CF0;
    --gold-bright: #7c3aed;
    --gold-dim: #23133a;
    --crimson: #c0392b;
    --crimson-bright: #e74c3c;
    --silver: #f6f6f6;
    --text: #fbfbfb;
    --text-dim: #7f8c8d;
    --emerald: #2ecc71;
    --sapphire: #3498db;
    --amethyst: #9b59b6;
    --font-display: 'Cinzel Decorative', serif;
    --font-heading: 'Cinzel', serif;
    --font-body: 'Crimson Text', serif;
  }

  html { scroll-behavior: smooth; }

  body {
    font-family: var(--font-body);
    background: var(--bg-deep);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
  }

  /* ===== AMBIENT BACKGROUND ===== */
  body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
      radial-gradient(ellipse 600px 400px at 20% 30%, rgba(163, 71, 212, 0.04) 0%, transparent 70%),
      radial-gradient(ellipse 500px 500px at 80% 70%, rgba(142, 43, 192, 0.03) 0%, transparent 70%),
      radial-gradient(ellipse 800px 600px at 50% 50%, rgba(38, 26, 46, 0.8) 0%, transparent 100%);
    pointer-events: none;
    z-index: 0;
  }

  /* Noise texture overlay */
  body::after {
    content: '';
    position: fixed;
    inset: 0;
    opacity: 0.025;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
  }

  /* ===== HEADER ===== */
  header {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px 20px 20px;
  }

  .logo {
    font-family: var(--font-display);
    font-size: clamp(2rem, 6vw, 3.5rem);
    font-weight: 900;
    color: var(--gold);
    letter-spacing: 0.15em;
    text-shadow:
      0 0 40px rgba(158, 71, 212, 0.3),
      0 2px 4px rgba(0,0,0,0.5);
    animation: logoReveal 1.2s ease-out;
  }

  .logo span { color: #af62c8; }

  .tagline {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--text-dim);
    letter-spacing: 0.4em;
    text-transform: uppercase;
    margin-top: 6px;
    animation: fadeUp 1s ease-out 0.3s both;
  }

  /* Decorative line */
  .divider {
    width: 200px;
    height: 1px;
    margin: 20px auto;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
    position: relative;
    animation: fadeUp 1s ease-out 0.5s both;
  }
  .divider::after {
    content: '◆';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--gold);
    font-size: 10px;
    background: var(--bg-deep);
    padding: 0 12px;
  }

  /* ===== MAIN LAYOUT ===== */
  main {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px 60px;
  }

  /* ===== DICE SELECTOR ===== */
  .dice-types {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    animation: fadeUp 0.8s ease-out 0.6s both;
  }

  .dice-btn {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 10px 20px;
    border: 1px solid var(--gold-dim);
    background: #9e47d40d;
    color: var(--gold);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.05em;
  }

  .dice-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(146, 71, 212, 0.15), transparent);
    opacity: 0;
    transition: opacity 0.3s;
  }

  .dice-btn:hover::before { opacity: 1; }
  .dice-btn:hover {
    border-color: var(--gold);
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(160, 71, 212, 0.15);
  }

  .dice-btn.active {
    background: linear-gradient(135deg, #23133a, rgba(137, 43, 192, 0.1));
    border-color: var(--gold-bright);
    color: var(--gold-bright);
    box-shadow: 0 0 20px rgba(163, 71, 212, 0.2), inset 0 0 20px rgba(144, 71, 212, 0.05);
  }

  /* ===== QUANTITY CONTROL ===== */
  .controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    margin-bottom: 30px;
    animation: fadeUp 0.8s ease-out 0.7s both;
  }

  .qty-label {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    color: var(--text-dim);
    letter-spacing: 0.1em;
    text-transform: uppercase;
  }

  .qty-control {
    display: flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    overflow: hidden;
  }

  .qty-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: #9e47d40d;
    color: var(--gold);
    font-family: var(--font-heading);
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .qty-btn:hover { background: #23133a; }

  .qty-display {
    width: 50px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    color: var(--text);
    background: rgba(0,0,0,0.3);
    border-left: 1px solid var(--gold-dim);
    border-right: 1px solid var(--gold-dim);
  }

  .modifier-section {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .modifier-input {
    width: 60px;
    height: 40px;
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    background: rgba(0,0,0,0.3);
    color: var(--text);
    font-family: var(--font-heading);
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
  }
  .modifier-input:focus { border-color: var(--gold); }

  /* ===== ROLL BUTTON ===== */
  .roll-section {
    text-align: center;
    margin-bottom: 40px;
    animation: fadeUp 0.8s ease-out 0.8s both;
  }

  .roll-btn {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    padding: 16px 60px;
    border: 2px solid var(--gold);
    background: linear-gradient(135deg, #3a1c63 0%, #684895 100%);
    color: var(--gold-bright);
    border-radius: 4px;
    cursor: pointer;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
  }

  .roll-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: radial-gradient(circle, rgba(170, 71, 212, 0.3), transparent);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.5s, height 0.5s;
  }

  .roll-btn:hover {
    transform: translateY(-3px);
    box-shadow:
      0 8px 30px rgba(158, 71, 212, 0.25),
      0 0 60px rgba(207, 71, 212, 0.1);
    text-shadow: 0 0 20px rgba(156, 71, 212, 0.5);
  }

  .roll-btn:hover::before { width: 300px; height: 300px; }

  .roll-btn:active {
    transform: translateY(0) scale(0.98);
  }

  .roll-btn.rolling {
    animation: shakeBtn 0.5s ease-in-out;
  }

  .roll-notation {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-dim);
    margin-top: 12px;
    letter-spacing: 0.08em;
  }

  /* ===== RESULTS AREA ===== */
  .results-container {
    min-height: 200px;
    position: relative;
  }

  .result-display {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(180deg, #3a1c63, #684895);
    border: 1px solid #5e309d;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
  }

  .result-display::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
  }

  .total-label {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    margin-bottom: 8px;
  }

  .total-value {
    font-family: var(--font-display);
    font-size: clamp(3rem, 10vw, 5rem);
    font-weight: 900;
    color: var(--gold-bright);
    text-shadow:
      0 0 40px rgba(167, 71, 212, 0.4),
      0 0 80px rgba(172, 71, 212, 0.2);
    line-height: 1;
    margin-bottom: 5px;
    transition: color 0.3s;
  }

  .total-value.crit {
    color: var(--crimson-bright);
    text-shadow: 0 0 40px rgba(231, 76, 60, 0.5), 0 0 80px rgba(231, 76, 60, 0.3);
    animation: critPulse 0.6s ease-out;
  }

  .total-value.nat20 {
    color: var(--emerald);
    text-shadow: 0 0 40px rgba(46, 204, 113, 0.5), 0 0 80px rgba(46, 204, 113, 0.3);
    animation: critPulse 0.6s ease-out;
  }

  .modifier-text {
    font-family: var(--font-heading);
    font-size: 1rem;
    color: var(--text-dim);
    margin-bottom: 4px;
  }

  /* Individual dice results */
  .dice-results {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
  }

  .die-result {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 6px;
    position: relative;
    animation: diePopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
  }

  .die-result:hover {
    transform: scale(1.15) rotate(-3deg);
    z-index: 2;
  }

  .die-result.d4 { background: linear-gradient(135deg, #3a1c6350, #4d3c6450); border: 1px solid #3a1c63; color: #aed6f1; clip-path: polygon(50% 0%, 0% 100%, 100% 100%); width: 60px; height: 54px; padding-top: 14px; }
  .die-result.d6 { background: linear-gradient(135deg, #2a1647, #382b4c); border: 1px solid #3a1c63; color: var(--gold-bright); border-radius: 8px; }
  .die-result.d8 { background: linear-gradient(135deg, #1f1232, #2d2639); border: 1px solid #3a1c63; color: #85c1e9; clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); width: 60px; height: 60px; }
  .die-result.d10 { background: linear-gradient(135deg, #23133a, #382f44); border: 1px solid #3a1c63; color: #d2b4de; clip-path: polygon(50% 0%, 95% 35%, 80% 100%, 20% 100%, 5% 35%); width: 60px; height: 60px; padding-top: 6px; }
  .die-result.d12 { background: linear-gradient(135deg, #2a1647, #382b4c); border: 1px solid #3a1c63; color: #abebc6; border-radius: 50%; }
  .die-result.d20 { background: linear-gradient(135deg, #1f1232, #2d2639); border: 1px solid var(--crimson); color: #f1948a; clip-path: polygon(50% 0%, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%); width: 62px; height: 62px; }
  .die-result.d100 { background: linear-gradient(135deg, #23133a, #382f44); border: 1px solid #3a1c63; color: #a3e4d7; border-radius: 50%; width: 62px; height: 62px; font-size: 0.95rem; }

  .die-result.is-max {
    box-shadow: 0 0 15px rgba(46, 204, 113, 0.4);
  }
  .die-result.is-min {
    box-shadow: 0 0 15px rgba(231, 76, 60, 0.3);
    opacity: 0.7;
  }

  /* ===== ROLL HISTORY ===== */
  .history-section {
    margin-top: 40px;
  }

  .history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
  }

  .history-title {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    color: var(--text-dim);
    letter-spacing: 0.3em;
    text-transform: uppercase;
  }

  .clear-btn {
    font-family: var(--font-heading);
    font-size: 0.7rem;
    color: var(--crimson);
    background: none;
    border: 1px solid rgba(192, 57, 43, 0.3);
    padding: 4px 12px;
    border-radius: 3px;
    cursor: pointer;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    transition: all 0.2s;
  }
  .clear-btn:hover {
    background: rgba(192, 57, 43, 0.1);
    border-color: var(--crimson);
  }

  .history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 260px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--gold-dim) transparent;
  }

  .history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: #23133a;
    border: 1px solid #3a1c63;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-size: 0.85rem;
    animation: slideIn 0.3s ease-out;
    transition: background 0.2s;
  }
  .history-item:hover { background: #5e309d; }

  .history-notation { color: var(--text-dim); letter-spacing: 0.05em; }
  .history-rolls { color: var(--text-dim); font-size: 0.78rem; flex: 1; text-align: center; padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .history-total { color: var(--gold); font-weight: 700; font-size: 1rem; min-width: 40px; text-align: right; }

  /* ===== QUICK ROLL PRESETS ===== */
  .presets {
    margin-top: 30px;
    text-align: center;
  }

  .presets-title {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    color: var(--text-dim);
    letter-spacing: 0.3em;
    text-transform: uppercase;
    margin-bottom: 12px;
  }

  .preset-chips {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }

  .preset-chip {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    padding: 6px 14px;
    border: 1px solid #3a1c63;
    background: #9e47d40d;
    color: var(--text-dim);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    letter-spacing: 0.05em;
  }
  .preset-chip:hover {
    border-color: var(--gold);
    color: var(--gold);
    background: #23133a;
    transform: translateY(-1px);
  }

  /* ===== STATS BAR ===== */
  .stats-bar {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-top: 30px;
    padding: 16px;
    border-top: 1px solid #3a1c63;
    animation: fadeUp 0.8s ease-out 1s both;
  }

  .stat {
    text-align: center;
  }

  .stat-val {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold);
  }

  .stat-label {
    font-family: var(--font-heading);
    font-size: 0.65rem;
    color: var(--text-dim);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-top: 2px;
  }

  /* ===== EMPTY STATE ===== */
  .empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--text-dim);
  }

  .empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
  }

  .empty-text {
    font-family: var(--font-heading);
    font-size: 0.9rem;
    letter-spacing: 0.1em;
  }

  /* ===== KEYBOARD HINT ===== */
  .keyboard-hint {
    text-align: center;
    margin-top: 10px;
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-dim);
    opacity: 0.5;
  }

  .keyboard-hint kbd {
    display: inline-block;
    padding: 2px 7px;
    border: 1px solid #3a1c63;
    border-radius: 3px;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    background: rgba(160, 71, 212, 0.05);
    color: #fff;
  }

  /* ===== FOOTER ===== */
  footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 30px 20px;
    font-family: var(--font-heading);
    font-size: 0.7rem;
    color: var(--text-dim);
    letter-spacing: 0.15em;
    opacity: 0.4;
  }

  /* ===== ANIMATIONS ===== */
  @keyframes logoReveal {
    from { opacity: 0; transform: translateY(-20px); letter-spacing: 0.5em; }
    to { opacity: 1; transform: translateY(0); letter-spacing: 0.15em; }
  }

  @keyframes fadeUp {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
  }

  @keyframes diePopIn {
    from { opacity: 0; transform: scale(0.3) rotate(180deg); }
    to { opacity: 1; transform: scale(1) rotate(0deg); }
  }

  @keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
  }

  @keyframes critPulse {
    0% { transform: scale(1); }
    40% { transform: scale(1.15); }
    100% { transform: scale(1); }
  }

  @keyframes shakeBtn {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-6px) rotate(-2deg); }
    30% { transform: translateX(5px) rotate(1.5deg); }
    45% { transform: translateX(-4px) rotate(-1deg); }
    60% { transform: translateX(3px) rotate(0.5deg); }
    75% { transform: translateX(-2px); }
  }

  @keyframes rollNumber {
    0% { opacity: 0.3; transform: translateY(-8px); }
    100% { opacity: 1; transform: translateY(0); }
  }

  /* ===== RESPONSIVE ===== */
  @media (max-width: 600px) {
    .dice-btn { padding: 8px 14px; font-size: 0.85rem; }
    .controls { flex-wrap: wrap; gap: 12px; }
    .roll-btn { padding: 14px 40px; font-size: 1.1rem; }
    .stats-bar { gap: 16px; flex-wrap: wrap; }
    .die-result { width: 46px; height: 46px; font-size: 0.95rem; }
    .die-result.d4 { width: 50px; height: 44px; }
    .die-result.d8, .die-result.d10, .die-result.d20 { width: 50px; height: 50px; }
    .die-result.d100 { width: 52px; height: 52px; }
  }