/* ============================================================
   Facemask Tool – Mobile-First CSS  (v5 — Dark Claymorphism)
   ============================================================ */

:root {
  --fm-bg:         #0d0d0d;
  --fm-surface:    #1a1a1a;
  --fm-surface2:   #242424;
  --fm-surface3:   #2e2e2e;
  --fm-accent:     #e8fd5a;
  --fm-accent-dk:  #c8dc3a;
  --fm-accent-dim: rgba(232,253,90,.12);
  --fm-danger:     #ff453a;
  --fm-success:    #32d74b;
  --fm-text:       #ffffff;
  --fm-text-sub:   #8e8e93;
  --fm-border:     rgba(255,255,255,.08);
  --fm-topbar-h:   56px;
  --fm-dlbar-h:    64px;
  --fm-radius:     22px;
  --fm-radius-sm:  12px;
  /* 3D shadow tokens */
  --fm-btn-shadow:
    0 1px 0 rgba(255,255,255,.07) inset,
    0 -1px 0 rgba(0,0,0,.5) inset,
    0 4px 10px rgba(0,0,0,.55),
    0 1px 3px rgba(0,0,0,.8);
  --fm-btn-shadow-active:
    0 0 0 rgba(255,255,255,.04) inset,
    0 -1px 0 rgba(0,0,0,.5) inset,
    0 1px 4px rgba(0,0,0,.7);
  --fm-accent-shadow:
    0 1px 0 rgba(255,255,255,.45) inset,
    0 -2px 0 rgba(0,0,0,.18) inset,
    0 6px 18px rgba(232,253,90,.35),
    0 2px 6px rgba(0,0,0,.35);
  --fm-accent-shadow-active:
    0 2px 0 rgba(0,0,0,.15) inset,
    0 -1px 0 rgba(255,255,255,.2) inset,
    0 2px 6px rgba(232,253,90,.2);
  --fm-panel-shadow:
    inset 0 1px 0 rgba(255,255,255,.05),
    0 -8px 32px rgba(0,0,0,.5);
}

/* ---------- Reset ---------- */
.facemask-app *,
.facemask-app *::before,
.facemask-app *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
.facemask-app button { cursor: pointer; }

/* ---------- App Container ---------- */
.facemask-app {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--fm-bg);
  min-height: 100svh;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--fm-text);
  overflow: hidden;
}

/* ---------- Screens ---------- */
.fm-screen {
  display: none;
  flex-direction: column;
  min-height: 100svh;
}
.fm-screen--active { display: flex; }

/* ============================================================
   Upload Screen
   ============================================================ */
.fm-upload-zone {
  margin: 28px 20px 0;
  background: var(--fm-surface);
  border: 1.5px dashed rgba(255,255,255,.15);
  border-radius: var(--fm-radius);
  padding: 48px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.fm-upload-zone:active,
.fm-upload-zone.fm-drag-over {
  border-color: var(--fm-accent);
  background: var(--fm-accent-dim);
}
.fm-upload-icon { font-size: 52px; }
.fm-upload-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--fm-text);
}
.fm-upload-sub {
  margin: 0;
  font-size: 13px;
  color: var(--fm-text-sub);
}
.fm-upload-formats {
  margin: 0;
  font-size: 12px;
  color: var(--fm-text-sub);
  opacity: .6;
}
#fm-file-input { display: none; }

.fm-how-to {
  margin: 16px 20px 0;
  background: var(--fm-surface);
  border-radius: var(--fm-radius);
  padding: 18px 20px;
}
.fm-how-to h3 {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--fm-text-sub);
  letter-spacing: .06em;
  text-transform: uppercase;
}
.fm-how-to ol {
  margin: 0;
  padding-left: 18px;
}
.fm-how-to li {
  font-size: 14px;
  color: var(--fm-text-sub);
  margin-bottom: 8px;
  line-height: 1.6;
}

/* ============================================================
   Editor Screen
   ============================================================ */

/* ---------- Topbar ---------- */
.fm-topbar {
  height: var(--fm-topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  background: var(--fm-bg);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
  border-bottom: 1px solid var(--fm-border);
}
.fm-topbar-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--fm-text);
  letter-spacing: .02em;
}
.fm-topbar-btn {
  height: 38px;
  min-width: 64px;
  padding: 0 12px;
  border: none;
  background: linear-gradient(180deg, #2e2e2e 0%, #1e1e1e 100%);
  border-radius: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--fm-text);
  transition: box-shadow .12s, transform .1s;
  box-shadow: var(--fm-btn-shadow);
}
.fm-topbar-btn:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.94);
}
.fm-topbar-btn-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--fm-text-sub);
  white-space: nowrap;
}

/* ---------- Canvas Area ---------- */
.fm-canvas-wrap {
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#facemask-canvas {
  display: block;
  touch-action: none;
}
.fm-overlay-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: rgba(255,255,255,.7);
  pointer-events: none;
  text-align: center;
  padding: 16px;
}

/* ---------- Loading ---------- */
.fm-loading {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 10;
}
.fm-loading--active { display: flex; }
.fm-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,.15);
  border-top-color: var(--fm-accent);
  border-radius: 50%;
  animation: fm-spin .8s linear infinite;
}
@keyframes fm-spin { to { transform: rotate(360deg); } }
.fm-loading-text {
  color: var(--fm-text-sub);
  font-size: 13px;
  margin: 0;
}

/* ============================================================
   Control Panel (Bottom Sheet)
   ============================================================ */
.fm-panel {
  background: var(--fm-surface);
  border-radius: 24px 24px 0 0;
  padding: 8px 16px 8px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--fm-panel-shadow);
}
.fm-panel-handle {
  width: 36px;
  height: 4px;
  background: var(--fm-surface3);
  border-radius: 2px;
  margin: 0 auto 12px;
}

/* ---------- Face Tabs ---------- */
.fm-face-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.fm-face-tabs::-webkit-scrollbar { display: none; }
.fm-face-tab {
  flex-shrink: 0;
  height: 32px;
  padding: 0 14px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #2e2e2e 0%, #1e1e1e 100%);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--fm-text-sub);
  font-weight: 600;
  transition: box-shadow .12s, transform .1s;
  box-shadow: var(--fm-btn-shadow);
}
.fm-face-tab:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.95);
}
.fm-face-tab--active {
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  font-weight: 700;
  box-shadow: var(--fm-accent-shadow);
}
.fm-face-tab--off {
  opacity: 0.35;
  text-decoration: line-through;
}
.fm-face-tab--add {
  color: var(--fm-accent);
  font-weight: 700;
  font-size: 16px;
  padding: 0 10px;
}

/* ---------- Context areas ---------- */
.fm-context { /* shown */ }
.fm-context--hidden { display: none; }

/* ---------- Mask Toggle Row ---------- */
.fm-mask-toggle-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 10px;
  border-bottom: 1px solid var(--fm-border);
  margin-bottom: 10px;
}
.fm-mask-toggle-row--visible { display: flex; }
.fm-mask-toggle-label {
  font-size: 13px;
  color: var(--fm-text-sub);
  font-weight: 500;
}
.fm-mask-toggle {
  position: relative;
  width: 50px;
  height: 28px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(180deg, #3ddd58 0%, #28a83e 100%);
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
  padding: 0;
  flex-shrink: 0;
  box-shadow:
    0 1px 0 rgba(255,255,255,.25) inset,
    0 4px 10px rgba(50,215,75,.4),
    0 2px 4px rgba(0,0,0,.4);
}
.fm-mask-toggle--off {
  background: linear-gradient(180deg, #333 0%, #222 100%);
  box-shadow:
    inset 0 2px 4px rgba(0,0,0,.5),
    0 1px 2px rgba(0,0,0,.4);
}
.fm-mask-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.4);
  transition: transform .2s;
}
.fm-mask-toggle:not(.fm-mask-toggle--off) .fm-mask-toggle-thumb {
  transform: translateX(22px);
}

/* ---------- Mask Type Tabs ---------- */
.fm-type-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 10px;
  background: var(--fm-bg);
  border-radius: var(--fm-radius-sm);
  padding: 4px;
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,.6),
    inset 0 1px 0 rgba(0,0,0,.8);
}
.fm-type-tab {
  flex: 1;
  height: 34px;
  border: none;
  background: transparent;
  font-size: 12px;
  cursor: pointer;
  color: var(--fm-text-sub);
  font-weight: 500;
  border-radius: 8px;
  transition: all .15s;
}
.fm-type-tab--active {
  background: linear-gradient(180deg, #2e2e2e 0%, #222 100%);
  color: var(--fm-text);
  font-weight: 700;
  box-shadow:
    0 1px 0 rgba(255,255,255,.07) inset,
    0 3px 8px rgba(0,0,0,.5),
    0 1px 2px rgba(0,0,0,.7);
}

/* ---------- Tab Panels ---------- */
.fm-tab-panel { display: block; }
.fm-tab-panel--hidden { display: none; }

/* ---------- Angle row visibility ---------- */
.fm-angle-row--hidden { display: none !important; }

/* ---------- Emoji Grid ---------- */
.fm-emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  max-height: 88px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 360px) {
  .fm-emoji-grid { grid-template-columns: repeat(7, 1fr); }
}
.fm-emoji-btn {
  aspect-ratio: 1;
  border: none;
  border-radius: 8px;
  background: linear-gradient(180deg, #2a2a2a 0%, #1e1e1e 100%);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .12s, transform .1s;
  padding: 0;
  box-shadow:
    0 1px 0 rgba(255,255,255,.06) inset,
    0 2px 5px rgba(0,0,0,.5),
    0 1px 2px rgba(0,0,0,.7);
}
.fm-emoji-btn:active {
  box-shadow: inset 0 2px 4px rgba(0,0,0,.6);
  transform: scale(.92);
}
.fm-emoji-btn--active {
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  box-shadow: var(--fm-accent-shadow);
  transform: scale(1.08);
}

/* ---------- PNG Grid ---------- */
.fm-png-panel-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.fm-png-upload-btn {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border: 1.5px dashed rgba(255,255,255,.2);
  border-radius: var(--fm-radius-sm);
  background: var(--fm-surface2);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  color: var(--fm-text-sub);
  transition: all .12s;
}
.fm-png-upload-btn:active {
  border-color: var(--fm-accent);
  background: var(--fm-accent-dim);
}
.fm-png-upload-icon {
  font-size: 22px;
  font-weight: 300;
  color: var(--fm-text-sub);
  line-height: 1;
}
.fm-png-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 136px;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  flex: 1;
  align-content: flex-start;
}
.fm-png-item {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border: 2px solid var(--fm-border);
  border-radius: var(--fm-radius-sm);
  background: var(--fm-surface2);
  cursor: pointer;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  transition: all .12s;
}
.fm-png-item img { width: 100%; height: 100%; object-fit: contain; }
.fm-png-item:active,
.fm-png-item--active {
  border-color: var(--fm-accent);
  background: var(--fm-accent-dim);
}
#fm-png-file-input { display: none; }

/* ---------- Blur Panel ---------- */
.fm-blur-types {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.fm-blur-type-btn {
  flex: 1;
  height: 36px;
  border: none;
  border-radius: var(--fm-radius-sm);
  background: linear-gradient(180deg, #2e2e2e 0%, #1e1e1e 100%);
  font-size: 13px;
  cursor: pointer;
  color: var(--fm-text-sub);
  font-weight: 600;
  transition: box-shadow .12s, transform .1s;
  box-shadow: var(--fm-btn-shadow);
}
.fm-blur-type-btn:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.97);
}
.fm-blur-type-btn--active {
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  font-weight: 700;
  box-shadow: var(--fm-accent-shadow);
}

/* ---------- Sliders ---------- */
.fm-slider-row,
.fm-size-row,
.fm-angle-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0 2px;
  border-top: 1px solid var(--fm-border);
  margin-top: 8px;
}
.fm-slider-row label,
.fm-size-row label,
.fm-angle-row label {
  font-size: 12px;
  color: var(--fm-text-sub);
  white-space: nowrap;
  min-width: 36px;
  font-weight: 600;
}
.fm-slider-row input[type="range"],
.fm-size-row input[type="range"],
.fm-angle-row input[type="range"] {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--fm-surface3);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f4ff80 0%, var(--fm-accent-dk) 100%);
  box-shadow:
    0 1px 0 rgba(255,255,255,.5) inset,
    0 4px 10px rgba(232,253,90,.45),
    0 2px 4px rgba(0,0,0,.4);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(180deg, #f4ff80 0%, var(--fm-accent-dk) 100%);
  border: none;
  box-shadow:
    0 4px 10px rgba(232,253,90,.45),
    0 2px 4px rgba(0,0,0,.4);
  cursor: pointer;
}
.fm-slider-val {
  font-size: 12px;
  color: var(--fm-text-sub);
  min-width: 34px;
  text-align: right;
  font-weight: 600;
}

/* ============================================================
   Text Mode Context
   ============================================================ */
.fm-text-mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--fm-border);
  margin-bottom: 10px;
}
.fm-text-mode-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--fm-accent);
}
.fm-text-mode-done {
  height: 30px;
  padding: 0 16px;
  border: none;
  border-radius: 15px;
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--fm-accent-shadow);
  transition: box-shadow .12s, transform .1s;
}
.fm-text-mode-done:active {
  box-shadow: var(--fm-accent-shadow-active);
  transform: scale(.95);
}

/* Text option tabs */
.fm-text-edit-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 10px;
  background: var(--fm-bg);
  border-radius: var(--fm-radius-sm);
  padding: 4px;
  box-shadow:
    inset 0 2px 6px rgba(0,0,0,.6),
    inset 0 1px 0 rgba(0,0,0,.8);
}
.fm-text-edit-tab {
  flex: 1;
  height: 30px;
  border: none;
  background: transparent;
  font-size: 11px;
  cursor: pointer;
  color: var(--fm-text-sub);
  font-weight: 500;
  border-radius: 8px;
  transition: all .15s;
}
.fm-text-edit-tab--active {
  background: linear-gradient(180deg, #2e2e2e 0%, #222 100%);
  color: var(--fm-text);
  font-weight: 700;
  box-shadow:
    0 1px 0 rgba(255,255,255,.07) inset,
    0 3px 8px rgba(0,0,0,.5),
    0 1px 2px rgba(0,0,0,.7);
}

/* Text pane (horizontal scroll single row) */
.fm-text-pane-wrap {
  min-height: 44px;
  margin-bottom: 2px;
}
.fm-text-pane {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.fm-text-pane::-webkit-scrollbar { display: none; }
.fm-text-pane--hidden { display: none; }

.fm-tpane-btn {
  flex-shrink: 0;
  height: 36px;
  min-width: 52px;
  border: none;
  border-radius: var(--fm-radius-sm);
  background: linear-gradient(180deg, #2e2e2e 0%, #1e1e1e 100%);
  font-size: 13px;
  font-weight: 600;
  color: var(--fm-text-sub);
  padding: 0 14px;
  transition: box-shadow .12s, transform .1s;
  box-shadow: var(--fm-btn-shadow);
}
.fm-tpane-btn:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.95);
}
.fm-tpane-btn--active {
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  font-weight: 700;
  box-shadow: var(--fm-accent-shadow);
}
.fm-tpane-sep {
  flex-shrink: 0;
  width: 1px;
  height: 24px;
  background: var(--fm-border);
  margin: 0 2px;
}
.fm-tpane-label {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--fm-text-sub);
  font-weight: 500;
  white-space: nowrap;
}
.fm-tpane-sc-btn {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.12);
  cursor: pointer;
  transition: transform .12s;
}
.fm-tpane-sc-btn--active {
  border-color: var(--fm-accent);
  transform: scale(1.2);
}
.fm-tpane-color-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.12);
  cursor: pointer;
  transition: transform .12s;
}
.fm-tpane-color-btn--active {
  border-color: var(--fm-accent);
  transform: scale(1.2);
}

/* ============================================================
   Text Add Bar
   ============================================================ */
.fm-text-add-bar {
  display: flex;
  gap: 8px;
  padding: 10px 0 4px;
  border-top: 1px solid var(--fm-border);
  margin-top: 8px;
}
.fm-text-input {
  flex: 1;
  height: 40px;
  border: none;
  border-radius: var(--fm-radius-sm);
  padding: 0 14px;
  font-size: 14px;
  outline: none;
  background: var(--fm-surface2);
  color: var(--fm-text);
  transition: background .2s;
}
.fm-text-input::placeholder { color: var(--fm-text-sub); }
.fm-text-input:focus { background: var(--fm-surface3); }
.fm-btn-add-text {
  flex-shrink: 0;
  height: 40px;
  padding: 0 18px;
  border: none;
  border-radius: var(--fm-radius-sm);
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: box-shadow .12s, transform .1s;
  box-shadow: var(--fm-accent-shadow);
}
.fm-btn-add-text:active {
  box-shadow: var(--fm-accent-shadow-active);
  transform: scale(.96);
}

/* Text list */
.fm-text-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}
.fm-text-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--fm-surface2);
  border-radius: var(--fm-radius-sm);
  padding: 8px 12px;
}
.fm-text-list-label {
  font-size: 13px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fm-text);
}
.fm-text-list-del {
  border: none;
  background: transparent;
  color: var(--fm-danger);
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

/* ============================================================
   Download Bar
   ============================================================ */
.fm-dl-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--fm-surface);
  border-top: 1px solid var(--fm-border);
  flex-shrink: 0;
  z-index: 15;
}
.fm-btn-share-x {
  flex: 1.2;
  height: 46px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, #2e2e2e 0%, #1c1c1c 100%);
  color: var(--fm-text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: box-shadow .12s, transform .1s;
  white-space: nowrap;
  letter-spacing: .01em;
  box-shadow: var(--fm-btn-shadow);
}
.fm-btn-share-x:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.97);
}
.fm-btn-dl {
  flex: 1;
  height: 46px;
  border: none;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: box-shadow .12s, transform .1s;
  white-space: nowrap;
}
.fm-btn-dl:active { transform: scale(.97); }
.fm-btn-dl--free {
  background: linear-gradient(180deg, #2a2a2a 0%, #1c1c1c 100%);
  color: var(--fm-text-sub);
  box-shadow: var(--fm-btn-shadow);
}
.fm-btn-dl--free:active { box-shadow: var(--fm-btn-shadow-active); }
.fm-btn-dl--hd {
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  box-shadow: var(--fm-accent-shadow);
}
.fm-btn-dl--hd:active { box-shadow: var(--fm-accent-shadow-active); }

/* ============================================================
   Ad Modal
   ============================================================ */
.fm-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: flex-end;
  justify-content: center;
}
.fm-modal--open { display: flex; }
.fm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(6px);
}
.fm-modal-box {
  position: relative;
  background: var(--fm-surface);
  border-radius: 28px 28px 0 0;
  width: 100%;
  max-width: 480px;
  padding: 28px 20px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: fm-slide-up .25s ease;
  border-top: 1px solid var(--fm-border);
}
@keyframes fm-slide-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.fm-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--fm-text);
}
.fm-modal-desc {
  margin: 0;
  font-size: 14px;
  color: var(--fm-text-sub);
  text-align: center;
}

/* ---------- AdSense Slot ---------- */
.fm-ad-slot {
  width: 100%;
  min-height: 100px;
  background: var(--fm-surface2);
  border-radius: var(--fm-radius-sm);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fm-adsense-unit { width: 100%; }

/* ---------- Countdown Ring ---------- */
.fm-countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.fm-countdown-ring {
  position: relative;
  width: 64px;
  height: 64px;
}
.fm-countdown-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.fm-countdown-track {
  fill: none;
  stroke: var(--fm-surface3);
  stroke-width: 3;
}
.fm-countdown-fill {
  fill: none;
  stroke: var(--fm-accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 113;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}
.fm-countdown-num {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--fm-accent);
}
.fm-countdown-label {
  margin: 0;
  font-size: 13px;
  color: var(--fm-text-sub);
}

/* ---------- Modal Buttons ---------- */
.fm-btn-dl-now {
  width: 100%;
  min-height: 52px;
  border: none;
  border-radius: 16px;
  background: linear-gradient(180deg, #f0ff6a 0%, var(--fm-accent-dk) 100%);
  color: #000;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: box-shadow .12s, transform .1s;
  box-shadow: var(--fm-accent-shadow);
}
.fm-btn-dl-now:not([disabled]):active {
  box-shadow: var(--fm-accent-shadow-active);
  transform: scale(.98);
}
.fm-btn-dl-now[disabled] {
  background: linear-gradient(180deg, #2a2a2a 0%, #1e1e1e 100%);
  color: var(--fm-text-sub);
  cursor: not-allowed;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.4);
}
.fm-btn-modal-cancel {
  border: none;
  background: transparent;
  font-size: 15px;
  color: var(--fm-text-sub);
  cursor: pointer;
  padding: 8px 20px;
}

/* ============================================================
   Toast
   ============================================================ */
.fm-toast {
  position: fixed;
  bottom: calc(var(--fm-dlbar-h) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(36,36,36,.95);
  color: var(--fm-text);
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  z-index: 200;
  max-width: calc(100vw - 32px);
  text-align: center;
  backdrop-filter: blur(12px);
  border: 1px solid var(--fm-border);
}
.fm-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
