/* ==========================================================================
   Yohaku PWA — Warm Gray Minimal Design System
   Palette & tactile surfaces aligned with Yohaku for macOS
   ========================================================================== */

:root {
  /* Surface palette sampled from Yohaku macOS */
  --bg-app: #f2f0ec;
  --bg-topbar: #eeece8;
  --bg-stage: #e1dfd9;
  --bg-bottom: #eceae6;
  --surface-card: #faf9f6;
  --surface-btn: #f7f6f3;
  --surface-btn-active: #ebe8e2;

  /* Canvas & slot */
  --paper: #fdfdfd;
  --slot-bg: #f5f3ef;
  --slot-bg-hover: #efeae2;
  --slot-dash: #cfc9bf;

  /* Borders */
  --border-hairline: #dfdcd6;
  --border-card: rgba(40, 38, 35, 0.09);
  --border-card-active: rgba(40, 38, 35, 0.22);

  /* Ink */
  --ink-primary: #282623;
  --ink-secondary: #6e6962;
  --ink-muted: #928c84;

  /* Action buttons */
  --cta-bg-disabled: #c4c0b9;
  --cta-fg-disabled: #f8f7f4;
  --cta-bg-ready: #2f2d29;
  --cta-bg-press: #1e1d1a;
  --cta-fg-ready: #fdfdfd;

  /* Shadows (3-layer elevation rings for light mode) */
  --shadow-border:
    0px 0px 0px 1px oklch(0 0 0 / 0.06),
    0px 1px 2px -1px oklch(0 0 0 / 0.06),
    0px 2px 4px 0px oklch(0 0 0 / 0.04);
  --shadow-border-hover:
    0px 0px 0px 1px oklch(0 0 0 / 0.08),
    0px 1px 2px -1px oklch(0 0 0 / 0.08),
    0px 2px 4px 0px oklch(0 0 0 / 0.06);
  --shadow-paper:
    0px 0px 0px 1px oklch(0 0 0 / 0.04),
    0px 12px 32px oklch(0.22 0.01 75 / 0.11),
    0px 2px 6px oklch(0.22 0.01 75 / 0.05);
  --shadow-card:
    0px 1px 3px oklch(0.22 0.01 75 / 0.07),
    0px 1px 1px oklch(0.22 0.01 75 / 0.04);

  /* Icon tokens */
  --icon-muted: #9e988f;
  --icon-active-frame: #5f5b55;
  --icon-active-fill: #4f4d4a;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "SF Pro Text", "Yu Gothic", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, monospace;

  /* Radii */
  --radius-sm: 8px;
  --radius-md: 11px;
  --radius-lg: 13px;
  --radius-pill: 999px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-app);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: none;
  background: none;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

button:focus-visible {
  outline: 2px solid var(--ink-primary);
  outline-offset: 2px;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   App Shell (Full single-screen mobile layout, centered on desktop)
   ========================================================================== */

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 540px;
  margin: 0 auto;
  background: var(--bg-stage);
  overflow: hidden;
  position: relative;
}

@media (min-width: 560px) {
  body {
    background: #d8d5ce;
  }
  .app {
    box-shadow: 0 0 40px rgba(40, 36, 30, 0.12);
    border-left: 1px solid var(--border-hairline);
    border-right: 1px solid var(--border-hairline);
  }
}

/* ==========================================================================
   Top Bar
   ========================================================================== */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--bg-topbar);
  border-bottom: 1px solid var(--border-hairline);
  z-index: 10;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.brand-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--ink-primary);
}

.brand-subtitle {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-secondary);
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 33px;
  padding-inline-start: 10px;
  padding-inline-end: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-btn);
  border: 1px solid transparent;
  box-shadow: var(--shadow-border);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-primary);
  transition: background-color 140ms ease-out, box-shadow 150ms ease-out, transform 100ms ease-out;
}

.pill-btn svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.pill-btn.icon-only {
  width: 33px;
  padding-inline: 0;
  color: var(--ink-secondary);
}

.pill-btn.icon-only svg {
  width: 17px;
  height: 17px;
}

.pill-btn:active {
  background: var(--surface-btn-active);
  transform: scale(0.97);
}

/* ==========================================================================
   Center Preview Stage
   ========================================================================== */

.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 18px;
  background: var(--bg-stage);
  position: relative;
  overflow: hidden;
  transition: background-color 0.15s ease;
}

.stage.is-dragover {
  background: #d6d3cb;
}

.paper-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.paper {
  position: relative;
  background: var(--paper);
  box-shadow: var(--shadow-paper);
  transition: width 0.18s ease, height 0.18s ease;
  flex-shrink: 0;
  overflow: hidden;
}

/* Interactive Photo Slot inside the #fdfdfd paper */
.slot {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--slot-bg);
  border: 1.5px dashed var(--slot-dash);
  overflow: hidden;
  cursor: pointer;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}

.slot:active {
  background: var(--slot-bg-hover);
}

.slot.is-dragover {
  background: #e9e4db;
  border-color: var(--ink-secondary);
}

.slot.has-image {
  background: transparent;
  border-color: transparent;
}

.slot-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  pointer-events: none;
}

.slot-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  text-align: center;
  pointer-events: none;
}

.slot-icon-badge {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: var(--surface-card);
  border: 1px solid transparent;
  box-shadow: var(--shadow-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-secondary);
}

.slot-icon-badge svg {
  width: 18px;
  height: 18px;
}

.slot-prompt {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-primary);
  line-height: 1.3;
}

.slot-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-muted);
  letter-spacing: -0.01em;
}

/* Compact placeholder adjustments for 2-up slots */
.paper.is-double .slot-placeholder {
  gap: 4px;
}

.paper.is-double .slot-icon-badge {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.paper.is-double .slot-icon-badge svg {
  width: 15px;
  height: 15px;
}

.paper.is-double .slot-prompt {
  font-size: 11px;
}

.paper.is-double .slot-sub {
  font-size: 9.5px;
}

/* Subtle clear button on filled slot */
.slot-clear {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: var(--radius-pill);
  background: rgba(40, 38, 35, 0.56);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fdfdfd;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.88;
  transition: opacity 0.12s ease, transform 0.1s ease;
  z-index: 2;
}

.slot-clear svg {
  width: 12px;
  height: 12px;
}

.slot-clear:active {
  transform: scale(0.9);
  opacity: 1;
}

/* Subtle slot position tag for 2-up filled state */
.slot-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(40, 38, 35, 0.52);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: #fdfdfd;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  pointer-events: none;
  z-index: 2;
}

/* ==========================================================================
   Bottom Thumb-Zone Control Dock
   ========================================================================== */

.dock {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg-app);
  border-top: 1px solid var(--border-hairline);
  z-index: 10;
}

.dock-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding: 0 2px;
}

.dock-status {
  display: flex;
  align-items: baseline;
  gap: 5px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-preset {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-primary);
}

.status-sep {
  color: var(--ink-muted);
  font-size: 11px;
}

.status-dims {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-secondary);
}

.status-note {
  font-size: 11px;
  color: var(--ink-muted);
  margin-left: 2px;
}

.dock-quick-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.mini-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 28px;
  padding-inline: 10px;
  border-radius: 7px;
  background: var(--surface-card);
  border: 1px solid transparent;
  box-shadow: var(--shadow-border);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-primary);
  transition: background-color 140ms ease-out, box-shadow 150ms ease-out, opacity 150ms ease-out, transform 100ms ease-out;
}

.mini-btn.has-icon {
  padding-inline-start: 8px;
  padding-inline-end: 10px;
}

.mini-btn svg {
  width: 13px;
  height: 13px;
}

.mini-btn:disabled {
  opacity: 0.42;
  cursor: default;
  box-shadow: none;
  border-color: var(--border-card);
}

.mini-btn:not(:disabled):active {
  background: var(--surface-btn-active);
  transform: scale(0.96);
}

/* 5-Preset Horizontal Selector (fits cleanly on 375px+ without scrolling) */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.preset-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 2px 7px;
  border-radius: var(--radius-md);
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-secondary);
  transition: background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, color 0.14s ease, transform 0.1s ease;
}

.preset-btn:active {
  transform: scale(0.96);
}

.preset-btn[aria-checked="true"] {
  background: var(--surface-card);
  border-color: var(--border-card-active);
  box-shadow: var(--shadow-card);
  color: var(--ink-primary);
}

.preset-glyph {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--icon-muted);
}

.preset-glyph svg {
  width: 24px;
  height: 24px;
  display: block;
}

.preset-glyph .glyph-outer {
  stroke: currentColor;
  fill: none;
}

.preset-glyph .glyph-inner {
  stroke: currentColor;
  fill: none;
}

.preset-btn[aria-checked="true"] .preset-glyph {
  color: var(--icon-active-frame);
}

.preset-btn[aria-checked="true"] .glyph-outer {
  stroke: currentColor;
  fill: var(--paper);
}

.preset-btn[aria-checked="true"] .glyph-inner {
  stroke: none;
  fill: var(--icon-active-fill);
}

.preset-name {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.preset-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: transparent;
  transition: background-color 0.14s ease;
}

.preset-btn[aria-checked="true"] .preset-dot {
  background: var(--ink-primary);
}

/* Primary Export Button */
.export-btn {
  width: 100%;
  height: 50px;
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: var(--cta-bg-ready);
  color: var(--cta-fg-ready);
  box-shadow: 0 2px 8px rgba(40, 36, 30, 0.14);
  transition: background-color 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.export-btn:disabled {
  background: var(--cta-bg-disabled);
  color: var(--cta-fg-disabled);
  box-shadow: none;
  cursor: default;
}

.export-btn:not(:disabled):active {
  background: var(--cta-bg-press);
  transform: scale(0.985);
}

.export-icon {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
}

.export-btn.is-exporting .export-icon {
  animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* ==========================================================================
   Spec Modal Sheet (Mac App "書き出し仕様" Card)
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(34, 31, 27, 0.36);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  z-index: 50;
}

/* Concentric radii: outer 24px = inner 10px (.spec-card) + 14px padding */
.spec-sheet {
  width: 100%;
  max-width: 440px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--bg-app);
  border-radius: 24px;
  border: 1px solid transparent;
  box-shadow:
    0px 0px 0px 1px oklch(0 0 0 / 0.08),
    0px 18px 44px oklch(0.2 0.01 75 / 0.22);
  padding: 14px;
}

.spec-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 2px 0;
  margin-bottom: 10px;
}

.spec-sheet-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-secondary);
  letter-spacing: 0.02em;
}

.spec-close-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-pill);
  background: var(--surface-btn);
  border: 1px solid transparent;
  box-shadow: var(--shadow-border);
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 140ms ease-out, box-shadow 150ms ease-out, color 140ms ease-out;
}

.spec-close-btn svg {
  width: 13px;
  height: 13px;
}

.spec-card {
  background: var(--surface-card);
  border: 1px solid transparent;
  box-shadow: var(--shadow-border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.spec-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
}

.spec-key {
  color: var(--ink-secondary);
  font-weight: 500;
}

.spec-val {
  color: var(--ink-primary);
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: right;
}

.spec-divider {
  height: 1px;
  background: var(--border-hairline);
  margin: 2px 0;
}

.spec-slot-line {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-secondary);
  line-height: 1.5;
}

.spec-privacy {
  margin: 12px 2px 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--ink-muted);
}

/* ==========================================================================
   Toast Notification
   ========================================================================== */

.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + env(safe-area-inset-top));
  transform: translate(-50%, -10px);
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  background: rgba(40, 38, 35, 0.9);
  color: #fdfdfd;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 60;
  box-shadow: 0 6px 20px rgba(30, 27, 23, 0.22);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Hover polish strictly for pointer devices (never latches on iOS touch) */
@media (hover: hover) {
  .pill-btn:hover {
    background: var(--surface-card);
    box-shadow: var(--shadow-border-hover);
  }
  .pill-btn.icon-only:hover {
    color: var(--ink-primary);
  }
  .slot:not(.has-image):hover {
    background: var(--slot-bg-hover);
    border-color: #bfb8ad;
  }
  .slot-clear:hover {
    opacity: 1;
    background: rgba(40, 38, 35, 0.72);
  }
  .mini-btn:not(:disabled):hover {
    background: var(--paper);
    box-shadow: var(--shadow-border-hover);
  }
  .preset-btn:not([aria-checked="true"]):hover {
    background: rgba(250, 249, 246, 0.55);
    color: var(--ink-primary);
  }
  .export-btn:not(:disabled):hover {
    background: #23211e;
  }
  .spec-close-btn:hover {
    background: var(--surface-card);
    box-shadow: var(--shadow-border-hover);
    color: var(--ink-primary);
  }
}

/* Small-screen tightening (iPhone SE / mini) */
@media (max-height: 690px) {
  .topbar {
    padding-top: calc(7px + env(safe-area-inset-top));
    padding-bottom: 7px;
  }
  .stage {
    padding: 10px 14px;
  }
  .dock {
    gap: 7px;
    padding-top: 8px;
  }
  .preset-btn {
    padding: 6px 2px 5px;
    gap: 4px;
  }
  .export-btn {
    height: 46px;
  }
}
