/* Fonts are loaded via <link> in index.html <head> */

      :root {
        --bg: #14120f;
        --surface: #1e1b16;
        --surface-2: #262119;
        --bead-idle: #3a342a;
        --bead-lit: #e8dcc4;
        --accent: #c97b3d;
        --accent-soft: rgba(201, 123, 61, 0.18);
        --text: #f2ede3;
        --text-muted: #8c8371;
        --border: #332d22;
        --danger: #b8583f;
      }

      * {
        box-sizing: border-box;
      }
      html,
      body {
        margin: 0;
        padding: 0;
      }
      @media (prefers-reduced-motion: reduce) {
        * {
          animation-duration: 0.001ms !important;
          transition-duration: 0.001ms !important;
        }
      }

      body {
        background: var(--bg);
        color: var(--text);
        font-family: "Inter", sans-serif;
        min-height: 100vh;
        display: flex;
        justify-content: center;
        position: relative;
        overflow-x: hidden;
      }

      .grain {
        position: fixed;
        inset: 0;
        pointer-events: none;
        opacity: 0.05;
        mix-blend-mode: overlay;
        z-index: 0;
      }

      .app {
        width: 100%;
        max-width: 420px;
        padding: 28px 20px 40px;
        position: relative;
        z-index: 1;
        display: flex;
        flex-direction: column;
        gap: 20px;
      }

      header {
        display: grid;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
      }
      .header-start {
        justify-self: start;
      }
      .wordmark {
        justify-self: center;
      }
      .header-actions {
        justify-self: end;
      }

      .weather-line {
        font-size: 12px;
        color: var(--text-muted);
        letter-spacing: 0.02em;
        text-align: center;
        min-height: 0;
        opacity: 0;
        transition: opacity 0.5s ease;
        margin-top: -8px;
      }
      .weather-line.visible {
        opacity: 1;
      }
      .wordmark {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 20px;
        letter-spacing: 0.02em;
        color: var(--text);
      }
      .wordmark .word {
        position: relative;
        display: inline-block;
      }
      .wordmark .scribble {
        position: absolute;
        left: -3px;
        bottom: -8px;
        width: calc(100% + 10px);
        height: 10px;
        overflow: visible;
      }
      .wordmark .scribble path {
        stroke: var(--accent);
        stroke-width: 2;
        fill: none;
        stroke-linecap: round;
      }

      .header-actions {
        display: flex;
        gap: 8px;
      }
      .icon-btn {
        background: none;
        border: 1px solid var(--border);
        color: var(--text-muted);
        width: 36px;
        height: 36px;
        border-radius: 50%;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 15px;
        transition:
          color 0.2s,
          border-color 0.2s,
          transform 0.2s;
        position: relative;
      }
      .icon-btn:hover {
        color: var(--text);
        border-color: var(--text-muted);
      }
      .icon-btn.pending {
        color: var(--danger);
        border-color: var(--danger);
        animation: pulse 1s ease-in-out infinite;
      }
      @keyframes pulse {
        0%,
        100% {
          transform: scale(1);
        }
        50% {
          transform: scale(1.08);
        }
      }

      /* Minus button gets its own bolder treatment so it reads clearly
         as "undo a tap" rather than blending in with the reset icon. */
      #minusBtn {
        border: 2px solid var(--accent);
        color: var(--accent);
        font-weight: 700;
        font-size: 18px;
      }
      #minusBtn:hover {
        background: var(--accent-soft);
        color: var(--text);
        border-color: var(--accent);
      }

      /* ============ SIDE NAVIGATION ============ */
      .nav-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.55);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
        z-index: 40;
      }
      .nav-overlay.visible {
        opacity: 1;
        pointer-events: auto;
      }
      .nav-drawer {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 250px;
        max-width: 78vw;
        background: var(--surface);
        border-right: 1px solid var(--border);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 50;
        display: flex;
        flex-direction: column;
        padding: 20px 0;
      }
      .nav-drawer.open {
        transform: translateX(0);
      }
      .nav-drawer-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 20px 16px;
        border-bottom: 1px solid var(--border);
        margin-bottom: 8px;
      }
      .nav-drawer-title {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 17px;
        color: var(--text);
      }
      .nav-close {
        background: none;
        border: none;
        color: var(--text-muted);
        font-size: 20px;
        cursor: pointer;
        line-height: 1;
        padding: 4px;
      }
      .nav-close:hover {
        color: var(--text);
      }
      .nav-link {
        display: block;
        padding: 13px 20px;
        color: var(--text-muted);
        text-decoration: none;
        font-family: "Inter", sans-serif;
        font-size: 15px;
        letter-spacing: 0.01em;
        border-left: 3px solid transparent;
        transition:
          color 0.15s,
          background 0.15s,
          border-color 0.15s;
      }
      .nav-link:hover {
        color: var(--text);
        background: var(--surface-2);
      }
      .nav-link.active {
        color: var(--accent);
        border-left-color: var(--accent);
        background: var(--surface-2);
      }

      .phrase-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 24px;
        padding: 30px 20px 22px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        cursor: pointer;
        user-select: none;
        -webkit-user-select: none;
        -webkit-tap-highlight-color: transparent;
        position: relative;
        transition:
          box-shadow 0.25s ease,
          transform 0.08s ease;
      }
      .phrase-card:active {
        transform: scale(0.997);
      }
      .phrase-card:focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 3px;
      }
      .phrase-card.celebrate {
        box-shadow:
          0 0 0 1px var(--accent),
          0 0 44px var(--accent-soft);
      }

      .arabic {
        font-family: "Amiri", serif;
        font-size: 34px;
        line-height: 1.3;
        direction: rtl;
        text-align: center;
      }
      .custom-phrase {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 27px;
        line-height: 1.3;
        text-align: center;
      }
      .translit {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 15px;
        color: var(--text-muted);
        letter-spacing: 0.02em;
      }

      .necklace-wrap {
        position: relative;
        width: 100%;
        max-width: 300px;
      }
      svg#necklace {
        width: 100%;
        height: auto;
        margin: 6px 0 -4px;
        overflow: visible;
        display: block;
      }

      .margin-note {
        position: absolute;
        top: 46%;
        left: 50%;
        transform: translate(-50%, -50%);
        font-family: "Caveat", cursive;
        font-size: 22px;
        font-weight: 600;
        color: var(--accent);
        line-height: 1;
        pointer-events: none;
        transition: opacity 0.5s ease;
        text-align: center;
        white-space: nowrap;
        animation: tapPulse 1.8s ease-in-out infinite;
      }
      .margin-note.gone {
        opacity: 0;
        animation: none;
      }
      @keyframes tapPulse {
        0%,
        100% {
          opacity: 0.75;
        }
        50% {
          opacity: 1;
        }
      }
      .bead {
        transition: fill 0.18s ease;
        transform-box: fill-box;
        transform-origin: center;
      }
      .bead.lit {
        fill: var(--bead-lit);
      }
      .bead.idle {
        fill: var(--bead-idle);
      }
      .bead.pop {
        animation: beadPop 0.35s ease;
      }
      @keyframes beadPop {
        0% {
          transform: scale(0.4);
        }
        55% {
          transform: scale(1.3);
        }
        100% {
          transform: scale(1);
        }
      }
      .imam-bead {
        fill: var(--accent);
      }
      .tassel {
        stroke: var(--border);
        stroke-width: 2;
      }

      .lap-info {
        font-size: 12px;
        color: var(--text-muted);
        letter-spacing: 0.08em;
        text-transform: uppercase;
      }
      .count-big {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 46px;
        line-height: 1;
        margin: 2px 0;
        font-variant-numeric: tabular-nums;
      }
      .meaning {
        font-size: 13px;
        color: var(--text-muted);
        text-align: center;
        min-height: 16px;
      }
      .footline {
        min-height: 20px;
        margin-top: 4px;
      }
      .hint {
        font-family: "Caveat", cursive;
        font-size: 16px;
        font-weight: 600;
        color: var(--accent);
        opacity: 0.75;
        transition: opacity 0.4s;
      }

      .toast {
        position: absolute;
        top: 14px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--accent);
        color: #1a1208;
        font-family: "Fraunces", serif;
        font-weight: 600;
        font-size: 13px;
        padding: 6px 14px;
        border-radius: 100px;
        opacity: 0;
        pointer-events: none;
        transition:
          opacity 0.3s,
          transform 0.3s;
        white-space: nowrap;
        display: flex;
        gap: 8px;
        align-items: center;
      }
      .toast.show {
        opacity: 1;
        transform: translateX(-50%) translateY(4px);
        pointer-events: auto;
      }
      .toast .toast-action {
        text-decoration: underline;
        cursor: pointer;
      }

      .chip-row {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: none;
        align-items: center;
      }
      .chip-row::-webkit-scrollbar {
        display: none;
      }

      .chip {
        flex: 0 0 auto;
        background: var(--surface);
        border: 1px solid var(--border);
        color: var(--text-muted);
        font-family: "Inter";
        font-size: 13px;
        padding: 9px 14px;
        border-radius: 100px;
        cursor: pointer;
        white-space: nowrap;
        transition: all 0.15s ease;
        display: flex;
        align-items: center;
        gap: 8px;
      }
      .chip:nth-child(odd) {
        transform: rotate(-1.1deg);
      }
      .chip:nth-child(even) {
        transform: rotate(0.9deg);
      }
      .chip.active,
      .chip:hover {
        transform: rotate(0deg);
      }
      .chip.active {
        background: var(--accent);
        color: #1a1208;
        border-color: var(--accent);
        font-weight: 600;
      }
      .chip:hover:not(.active) {
        border-color: var(--text-muted);
        color: var(--text);
      }
      .chip .dot {
        width: 5px;
        height: 5px;
        border-radius: 50%;
        background: currentColor;
        opacity: 0.5;
      }
      .chip .del {
        opacity: 0.55;
        padding-left: 2px;
        font-size: 14px;
        line-height: 1;
      }
      .chip .del:hover {
        opacity: 1;
        color: var(--danger);
      }
      .add-track-btn {
        width: 100%;
        margin-top: 10px;
        background: none;
        border: 1px dashed var(--border);
        color: var(--accent);
        font-family: "Inter";
        font-size: 13px;
        font-weight: 600;
        padding: 11px;
        border-radius: 14px;
        cursor: pointer;
        transition: all 0.15s ease;
      }
      .add-track-btn:hover {
        background: var(--accent-soft);
        border-color: var(--accent);
      }

      .stats {
        display: flex;
        justify-content: space-between;
        border-top: 1px solid var(--border);
        padding-top: 16px;
        margin-top: 4px;
      }
      .stat {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        flex: 1;
      }
      .stat span {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 22px;
        font-variant-numeric: tabular-nums;
      }
      .stat label {
        font-size: 10px;
        color: var(--text-muted);
        letter-spacing: 0.08em;
        text-transform: uppercase;
      }
      .stat.clickable {
        cursor: pointer;
        border-radius: 10px;
        padding: 4px 6px;
        margin: -4px -6px;
        transition:
          background 0.15s,
          transform 0.15s;
      }
      .stat.clickable:hover {
        background: var(--surface-2);
      }
      .stat.clickable:active {
        transform: scale(0.97);
      }
      .stat.clickable.pending span {
        color: var(--danger);
        animation: pulse 1s ease-in-out infinite;
      }
      .stat.clickable.pending label::after {
        content: " — tap to confirm";
        color: var(--danger);
      }

      .section-label {
        font-size: 11px;
        color: var(--text-muted);
        letter-spacing: 0.1em;
        text-transform: uppercase;
        padding-left: 2px;
        margin-bottom: 8px;
      }

      .colophon {
        font-family: "Caveat", cursive;
        font-size: 16px;
        color: var(--text-muted);
        opacity: 0.7;
        text-align: center;
        margin-top: -4px;
        transform: rotate(-0.6deg);
      }

      .modal-overlay {
        position: fixed;
        inset: 0;
        background: rgba(10, 8, 6, 0.6);
        backdrop-filter: blur(3px);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 50;
        opacity: 1;
        transition: opacity 0.2s ease;
        padding: 20px;
      }
      .modal-overlay.hidden {
        opacity: 0;
        pointer-events: none;
      }
      .modal-card {
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: 20px;
        padding: 22px;
        width: min(360px, 100%);
        display: flex;
        flex-direction: column;
        gap: 12px;
      }
      .modal-title {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 18px;
      }
      .modal-sub {
        font-size: 12px;
        color: var(--text-muted);
        margin-top: -8px;
      }
      .field-label {
        font-size: 11px;
        color: var(--text-muted);
        letter-spacing: 0.06em;
        text-transform: uppercase;
      }
      .field-input {
        background: var(--bg);
        border: 1px solid var(--border);
        color: var(--text);
        border-radius: 10px;
        padding: 11px 13px;
        font-family: "Inter";
        font-size: 14px;
        outline: none;
        transition: border-color 0.15s;
      }
      .field-input:focus {
        border-color: var(--accent);
      }
      .modal-actions {
        display: flex;
        justify-content: flex-end;
        gap: 8px;
        margin-top: 6px;
      }
      .btn {
        border-radius: 10px;
        padding: 10px 16px;
        font-family: "Inter";
        font-size: 13px;
        font-weight: 600;
        cursor: pointer;
        border: 1px solid transparent;
      }
      .btn-ghost {
        background: none;
        border-color: var(--border);
        color: var(--text-muted);
      }
      .btn-ghost:hover {
        color: var(--text);
      }
      .btn-primary {
        background: var(--accent);
        color: #1a1208;
      }
      .btn-primary:disabled {
        opacity: 0.4;
        cursor: not-allowed;
      }

      .visually-hidden {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
      }

      /* ============ SHARED PAGE SHELL (non-counter pages) ============ */
      .page-title {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 26px;
        text-align: center;
        margin: 4px 0 2px;
      }
      .page-sub {
        font-size: 13px;
        color: var(--text-muted);
        text-align: center;
        margin-bottom: 8px;
      }
      .placeholder-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 24px;
        padding: 44px 24px;
        text-align: center;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
      }
      .placeholder-card .glyph {
        font-size: 30px;
        opacity: 0.7;
      }
      .placeholder-card p {
        color: var(--text-muted);
        font-size: 14px;
        max-width: 280px;
        line-height: 1.5;
        margin: 0;
      }

      .names-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
      }
      @media (min-width: 480px) {
        .names-grid {
          grid-template-columns: 1fr 1fr 1fr;
        }
      }
      .name-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 14px;
        padding: 14px 10px;
        text-align: center;
        display: flex;
        flex-direction: column;
        gap: 3px;
      }
      .name-card .num {
        font-size: 10px;
        color: var(--text-muted);
        letter-spacing: 0.06em;
      }
      .name-card .arabic-name {
        font-family: "Amiri", serif;
        font-size: 21px;
        direction: rtl;
      }
      .name-card .translit-name {
        font-family: "Fraunces", serif;
        font-weight: 500;
        font-size: 13px;
      }
      .name-card .meaning-name {
        font-size: 11px;
        color: var(--text-muted);
        line-height: 1.3;
      }