/* ============================================================
   Facemask Tool – Light Theme CSS  (v6 — Site Match)
   ============================================================ */

:root {
  --fm-bg:         #f5f5f7;
  --fm-surface:    #ffffff;
  --fm-surface2:   #f2f2f7;
  --fm-surface3:   #e5e5ea;
  --fm-accent:     #e8417a;
  --fm-accent-dk:  #c4306a;
  --fm-accent-dim: rgba(232,65,122,.10);
  --fm-danger:     #ff3b30;
  --fm-success:    #34c759;
  --fm-text:       #1c1c1e;
  --fm-text-sub:   #6e6e73;
  --fm-border:     rgba(0,0,0,.09);
  --fm-topbar-h:   56px;
  --fm-dlbar-h:    64px;
  --fm-radius:     16px;
  --fm-radius-sm:  10px;
  --fm-btn-shadow:
    0 1px 3px rgba(0,0,0,.10),
    0 1px 0 rgba(255,255,255,.9) inset;
  --fm-btn-shadow-active:
    inset 0 1px 3px rgba(0,0,0,.14);
  --fm-accent-shadow:
    0 4px 14px rgba(232,65,122,.30),
    0 1px 3px rgba(0,0,0,.08);
  --fm-accent-shadow-active:
    0 2px 6px rgba(232,65,122,.18);
  --fm-panel-shadow:
    0 -2px 12px rgba(0,0,0,.06);
}

/* ---------- 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(0,0,0,.18);
  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;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.fm-upload-zone:active,
.fm-upload-zone.fm-upload-zone--drag {
  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: .7;
}
#fm-file-input { display: none; }

.fm-how-to {
  margin: 16px 20px 0;
  background: var(--fm-surface);
  border-radius: var(--fm-radius);
  padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.fm-how-to h3 {
  margin: 0 0 12px;
  font-size: 13px;
  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-surface);
  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: 36px;
  min-width: 64px;
  padding: 0 12px;
  border: 1px solid var(--fm-border);
  background: var(--fm-surface);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  color: var(--fm-text);
  transition: box-shadow .12s, transform .1s, background .1s;
  box-shadow: var(--fm-btn-shadow);
}
.fm-topbar-btn:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.95);
  background: var(--fm-surface2);
}
.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: #f0f0f0;
  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(0,0,0,.5);
  pointer-events: none;
  text-align: center;
  padding: 16px;
}

/* ---------- Loading ---------- */
.fm-loading {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.80);
  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(0,0,0,.10);
  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: 20px 20px 0 0;
  padding: 8px 16px 8px;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--fm-panel-shadow);
  border-top: 1px solid var(--fm-border);
}
.fm-panel-handle {
  width: 36px;
  height: 4px;
  background: var(--fm-surface3);
  border-radius: 2px;
  margin: 0 auto 12px;
}

/* ---------- Add Button Row ---------- */
.fm-add-btn-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.fm-add-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  border-radius: var(--fm-radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: box-shadow .12s, transform .1s;
}
.fm-add-btn:active {
  transform: scale(.97);
  box-shadow: var(--fm-btn-shadow-active);
}
.fm-add-btn--stamp {
  background: var(--fm-accent);
  color: #fff;
  box-shadow: var(--fm-accent-shadow);
}
.fm-add-btn--stamp:active {
  box-shadow: var(--fm-accent-shadow-active);
}
.fm-add-btn--mosaic {
  background: var(--fm-surface2);
  color: var(--fm-text);
  border: 1px solid var(--fm-border);
  box-shadow: var(--fm-btn-shadow);
}
.fm-add-btn-icon { font-size: 18px; line-height: 1; }
.fm-add-btn-label { white-space: nowrap; }

/* ---------- 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: 1px solid var(--fm-border);
  border-radius: 16px;
  background: var(--fm-surface);
  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(.96);
}
.fm-face-tab--active {
  background: var(--fm-accent);
  color: #fff;
  border-color: var(--fm-accent);
  font-weight: 700;
  box-shadow: var(--fm-accent-shadow);
}
.fm-face-tab--off {
  opacity: 0.4;
  text-decoration: line-through;
}
.fm-face-tab--add {
  color: var(--fm-accent);
  border-color: var(--fm-accent-dim);
  background: var(--fm-accent-dim);
  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: var(--fm-accent);
  cursor: pointer;
  transition: background .2s, box-shadow .2s;
  padding: 0;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(232,65,122,.30);
}
.fm-mask-toggle--off {
  background: var(--fm-surface3);
  box-shadow: inset 0 1px 3px rgba(0,0,0,.12);
}
.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,.20);
  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-surface2);
  border-radius: var(--fm-radius-sm);
  padding: 3px;
  border: 1px solid var(--fm-border);
}
.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: var(--fm-surface);
  color: var(--fm-text);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
}

/* ---------- 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: 1px solid var(--fm-border);
  border-radius: 8px;
  background: var(--fm-surface);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: box-shadow .12s, transform .1s;
  padding: 0;
  box-shadow: var(--fm-btn-shadow);
}
.fm-emoji-btn:active {
  box-shadow: var(--fm-btn-shadow-active);
  transform: scale(.92);
}
.fm-emoji-btn--active {
  background: var(--fm-accent-dim);
  border-color: var(--fm-accent);
  box-shadow: 0 0 0 2px var(--fm-accent);
  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(0,0,0,.18);
  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: 1px solid var(--fm-border);
  border-radius: var(--fm-radius-sm);
  background: var(--fm-surface);
  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: var(--fm-accent);
  color: #fff;
  border-color: var(--fm-accent);
  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: 38px;
  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;
  direction: ltr;      /* RTL継承によるスライダー反転を防止 */
  writing-mode: horizontal-tb;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--fm-accent);
  box-shadow: 0 2px 8px rgba(232,65,122,.35);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--fm-accent);
  border: none;
  box-shadow: 0 2px 8px rgba(232,65,122,.35);
  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: var(--fm-accent);
  color: #fff;
  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-surface2);
  border-radius: var(--fm-radius-sm);
  padding: 3px;
  border: 1px solid var(--fm-border);
}
.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: var(--fm-surface);
  color: var(--fm-text);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(0,0,0,.10);
}

/* Text pane */
.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: 1px solid var(--fm-border);
  border-radius: var(--fm-radius-sm);
  background: var(--fm-surface);
  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: var(--fm-accent);
  color: #fff;
  border-color: var(--fm-accent);
  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(0,0,0,.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(0,0,0,.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: 1px solid var(--fm-border);
  border-radius: var(--fm-radius-sm);
  padding: 0 14px;
  font-size: 14px;
  outline: none;
  background: var(--fm-surface2);
  color: var(--fm-text);
  transition: border-color .2s, background .2s;
}
.fm-text-input::placeholder { color: var(--fm-text-sub); opacity: .7; }
.fm-text-input:focus {
  border-color: var(--fm-accent);
  background: var(--fm-surface);
}
.fm-btn-add-text {
  flex-shrink: 0;
  height: 40px;
  padding: 0 18px;
  border: none;
  border-radius: var(--fm-radius-sm);
  background: var(--fm-accent);
  color: #fff;
  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;
  border: 1px solid var(--fm-border);
}
.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: 1px solid var(--fm-border);
  border-radius: 14px;
  background: var(--fm-surface);
  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: var(--fm-surface2);
  color: var(--fm-text-sub);
  border: 1px solid var(--fm-border);
  box-shadow: var(--fm-btn-shadow);
}
.fm-btn-dl--free:active { box-shadow: var(--fm-btn-shadow-active); }
.fm-btn-dl--hd {
  background: var(--fm-accent);
  color: #fff;
  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,.4);
  backdrop-filter: blur(4px);
}
.fm-modal-box {
  position: relative;
  background: var(--fm-surface);
  border-radius: 24px 24px 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);
  box-shadow: 0 -4px 24px rgba(0,0,0,.10);
}
@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;
  border: 1px solid var(--fm-border);
}
.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: var(--fm-accent);
  color: #fff;
  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: var(--fm-surface3);
  color: var(--fm-text-sub);
  cursor: not-allowed;
  box-shadow: none;
}
.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(28,28,30,.90);
  color: #fff;
  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(8px);
}
.fm-toast--visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Responsive – Tablet / Desktop (≥ 768px)
   ============================================================ */
@media (min-width: 768px) {

  .facemask-app {
    max-width: 1080px;
    min-height: auto;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,.10);
    margin: 32px auto;
    border: 1px solid var(--fm-border);
  }

  .fm-upload-zone {
    padding: 72px 40px;
    margin: 40px 32px 0;
  }
  .fm-how-to {
    margin: 20px 32px 32px;
  }

  #fm-editor-screen {
    flex-direction: row;
    flex-wrap: wrap;
    min-height: auto;
  }

  .fm-topbar {
    flex: 0 0 100%;
  }

  .fm-canvas-wrap {
    flex: 1 1 auto;
    height: calc(100svh - var(--fm-topbar-h) - var(--fm-dlbar-h) - 64px);
    min-height: 360px;
    max-height: 720px;
    background: #e8e8ed;
  }

  .fm-panel {
    flex: 0 0 320px;
    width: 320px;
    border-radius: 0;
    height: calc(100svh - var(--fm-topbar-h) - var(--fm-dlbar-h) - 64px);
    min-height: 360px;
    max-height: 720px;
    overflow-y: auto;
    border-left: 1px solid var(--fm-border);
    border-top: none;
    padding: 12px 16px 16px;
    box-shadow: none;
  }

  .fm-panel-handle { display: none; }

  .fm-dl-bar {
    flex: 0 0 100%;
  }

  .fm-modal {
    align-items: center;
  }
  .fm-modal-box {
    border-radius: 20px;
    max-width: 420px;
    padding: 32px 28px;
  }
  @keyframes fm-slide-up {
    from { transform: translateY(16px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
}
