* { box-sizing: border-box; }

:root {
  /* Sakuolia palette -- white ground, navy ink, moonlight-blue accent */
  --paper:        #ffffff;
  --surface:      #ffffff;
  --surface-dim:  #f2f4f8;
  --border:       #e2e6ee;

  /* ink -- cool navy-leaning text */
  --ink:          #24304c;
  --ink-strong:   #17223c;
  --ink-dim:      #5f6b84;
  --navy:         #1b2a4a;
  --accent:       #3568b0;

  /* burn-in orange -- reserved for things that actually emit light:
     the canvas stamp, the LCD date island, the header's brand-date,
     the favicon, and the demo card's canvas content. Never used for UI
     chrome (buttons/switches/toggles/sliders/tabs/labels/toast). */
  --burn:         #ff9a2e;
  --burn-ink:     #b05c08;

  /* databack LCD island */
  --lcd-bg:       #17130e;
  --lcd-glow:     #ff9a2e;

  --shadow-card:  0 2px 12px rgba(51, 49, 44, 0.08);
  --shadow-photo: 0 6px 28px rgba(51, 49, 44, 0.18);
  --radius:       14px;
  --radius-sm:    10px;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", Georgia, serif;
  line-height: 1.7;
  font-size: 15px;
}

.dseg {
  font-family: "DSEG7 Classic", monospace;
  font-style: italic;
}

a, button, input, [role="tab"], [role="switch"], summary {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

/* ============ header ============ */
#siteHeader {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
}

.brand-name {
  font-size: 18px;
  color: var(--navy);
  letter-spacing: 0.14em;
  font-weight: 700;
}

.brand-by {
  font-size: 11px;
  color: var(--ink-dim);
  letter-spacing: 0.1em;
  font-weight: 400;
  margin-left: 2px;
}

.brand-date {
  font-size: 12px;
  color: var(--burn-ink);
  margin-left: 10px;
  text-shadow: 0 0 4px rgba(255, 154, 46, 0.45);
}

/* ============ welcome screen ============ */
#welcome {
  padding: 0;
  text-align: center;
}

#welcome[hidden] { display: none; }

/* navy hero band, echoing the Sakuolia Works portal */
.hero {
  background: var(--navy);
  color: #fff;
  padding: 44px 20px 40px;
}

.hero h1 {
  color: #fff;
  font-weight: 400;
  font-size: 24px;
  letter-spacing: 0.1em;
  margin: 0 0 8px;
}

.hero-en {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  letter-spacing: 0.16em;
  font-style: italic;
  margin: 0;
}

@media (min-width: 768px) {
  .hero { padding: 64px 20px 56px; }
  .hero h1 {
    font-size: 30px;
    letter-spacing: 0.12em;
  }
  .hero-en { font-size: 13px; }
}

.welcome-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 28px 20px 12px;
}

/* section title with the portal's short blue underline */
.section-title {
  font-size: 20px;
  font-weight: 400;
  color: var(--ink-strong);
  letter-spacing: 0.08em;
  margin: 40px 0 18px;
  padding-bottom: 12px;
  position: relative;
}

.section-title::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 36px;
  height: 2px;
  background: var(--accent);
}

#welcome .lead {
  color: var(--ink-dim);
  font-size: 15px;
  margin: 0 0 8px;
}

.demo-print {
  background: #fff;
  padding: 10px 10px 34px;
  border-radius: 4px;
  box-shadow: var(--shadow-photo);
  transform: rotate(-2deg);
  max-width: 420px;
  margin: 24px auto;
  opacity: 0;
  translate: 0 8px;
  transition: opacity 0.4s ease, translate 0.4s ease;
}

.demo-print.in {
  opacity: 1;
  translate: 0 0;
}

.demo-print canvas {
  display: block;
  width: 100%;
  border-radius: 2px;
}

.demo-print figcaption {
  font-size: 13px;
  color: var(--ink-dim);
  text-align: center;
  margin-top: 8px;
}

button.primary.xl {
  display: block;
  width: 100%;
  height: 52px;
  font-size: 17px;
  font-weight: 700;
  background: var(--ink-strong);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}

button.primary.xl:hover { filter: brightness(1.15); }
button.primary.xl:active { transform: scale(0.98); }

.link-btn.center {
  display: block;
  margin: 14px auto 0;
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
  text-underline-offset: 2px;
  cursor: pointer;
  min-height: 44px;
}

.link-btn.center:hover,
.link-btn.center:focus-visible {
  text-decoration: underline;
}

.steps {
  list-style: none;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 0;
  margin: 0 0 28px;
  color: var(--ink-dim);
  font-size: 13px;
}

.steps li {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--ink-dim);
  font-size: 13px;
  flex-shrink: 0;
}

/* If 375px still can't fit three steps on one line, shrink the label text
   rather than wrap -- Zen Kurenaido's 12px-minimum rule is waived for these
   three short labels only. */
@media (max-width: 380px) {
  .steps { font-size: 12px; gap: 10px; }
}

.privacy {
  font-size: 13px;
  color: var(--ink-dim);
  margin: 0 0 24px;
}

.site-footer {
  background: var(--navy);
  color: rgba(255, 255, 255, 0.85);
  font-size: 13px;
  text-align: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px));
  margin-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.footer-brand {
  letter-spacing: 0.14em;
}

.footer-copy {
  font-size: 11px;
  opacity: 0.65;
  letter-spacing: 0.06em;
}

/* drop-over highlight on the welcome screen */
body.dragging-over #welcome {
  outline: 3px dashed var(--navy);
  outline-offset: -12px;
}

#dragOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
}

#dragOverlay[hidden] { display: none; }

#dragOverlay p {
  font-size: 20px;
  color: var(--navy);
  font-weight: 500;
  background: #fff;
  padding: 18px 28px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}

/* ============ editor screen ============ */
#editor {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 60px);
  height: calc(100dvh - 60px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#editor.in { opacity: 1; }

#editor[hidden] { display: none; }

#stage {
  position: relative;
  flex: 1;
  min-height: 20dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  overflow: hidden;
  background: var(--paper);
}

/* display:contents removes the frame's own box so the canvas becomes a direct
   flex child of #stage (which has a definite height). That lets the canvas's
   percentage max-height resolve against the stage, so a portrait photo is
   constrained on BOTH axes and keeps its exact aspect ratio. The "print frame"
   white border now lives on the canvas itself as a content-box border, so it
   hugs the photo tightly on every side and never distorts the bitmap. */
#printFrame {
  display: contents;
}

#previewCanvas {
  display: block;
  box-sizing: content-box;
  border: 8px solid #fff;
  border-radius: 3px;
  box-shadow: var(--shadow-photo);
  /* -16px leaves room for the 8px border on each axis so the bordered box
     still fits the stage without overflowing. */
  max-width: calc(100% - 16px);
  max-height: calc(100% - 16px);
}

/* When the white print border is baked into the canvas pixels (print mode),
   drop the CSS border so it isn't drawn twice. */
#printFrame.no-pad #previewCanvas {
  border: 0;
  border-radius: 2px;
  max-width: 100%;
  max-height: 100%;
}

#toast {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border);
  max-width: 90vw;
  text-align: center;
}

#toast[hidden] { display: none; }

/* ---- panel / bottom sheet ---- */
#panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  max-height: 70dvh;
  transition: max-height 0.25s ease;
}

#panel[hidden] { display: none; }

#panel.collapsed {
  max-height: 96px;
}

.sheet-handle {
  flex: none;
  width: 100%;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
}

.sheet-handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#panel.collapsed .panel-body {
  overflow: hidden;
}

/* ---- tabs ---- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 14px;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-dim);
  font-size: 14px;
  padding: 12px 6px;
  cursor: pointer;
  min-height: 44px;
}

.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 500;
}

.tab-panels {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tab-panel[hidden] { display: none; }

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- persistent row ---- */
.persistent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.field-inline label {
  font-size: 13px;
  color: var(--ink-dim);
}

.field-inline .toggle {
  margin-top: 0;
  width: auto;
}

.buttons {
  display: flex;
  gap: 10px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

/* ============ form controls ============ */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 13px;
  color: var(--ink-dim);
  display: flex;
  justify-content: space-between;
}

.field label span {
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity 0.15s ease;
}

.field-group.disabled {
  opacity: 0.45;
}

.field-group.disabled .field,
.field-group.disabled .accordion {
  pointer-events: none;
}

/* ---- master / sub switches ---- */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}

.switch-row label {
  font-size: 14px;
  color: var(--ink);
}

.switch-row.sub label {
  font-size: 13px;
  color: var(--ink-dim);
}

input[type="checkbox"][role="switch"] {
  -webkit-appearance: none;
  appearance: none;
  width: 48px;
  height: 28px;
  border-radius: 14px;
  background: #d3d9e4;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease;
}

input[type="checkbox"][role="switch"]::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: var(--shadow-card);
  transition: transform 0.15s ease;
}

input[type="checkbox"][role="switch"]:checked {
  background: var(--ink-strong);
}

input[type="checkbox"][role="switch"]:checked::before {
  transform: translateX(20px);
}

/* ---- text inputs ---- */
input[type="text"] {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}

input[type="text"]:focus {
  border-color: var(--navy);
}

#messageText {
  font-size: 17px;
}

#messageText::placeholder,
#captionLine1::placeholder,
#captionLine2::placeholder {
  color: var(--ink-dim);
  opacity: 0.6;
  font-style: italic;
}

/* Only shown while both caption lines are empty, so the "例：" placeholder
   text in captionLine1/2 isn't mistaken for real auto-filled EXIF data that
   will actually be burned into the photo (UI_SPEC.md §4.6). */
.field-hint {
  font-size: 12px;
  color: var(--ink-dim);
  margin: 4px 0 0;
}

.field-hint[hidden] { display: none; }

/* ---- LCD date input island (the one deliberately dark element) ---- */
.date-input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.date-input-row .lcd-text {
  flex: 1;
  min-width: 0;
}

#dateText.lcd-text {
  background: var(--lcd-bg);
  border: 1px solid #000;
  border-radius: var(--radius-sm);
  color: var(--lcd-glow);
  font-size: 22px;
  letter-spacing: 0.05em;
  text-shadow: 0 0 8px rgba(255, 154, 46, 0.5);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

#dateText.lcd-text:focus {
  border-color: var(--burn-ink);
}

.date-picker-btn.lcd {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--lcd-bg);
  border: 1px solid #000;
  border-radius: var(--radius-sm);
  color: var(--lcd-glow);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.5);
}

.date-picker-btn.lcd:focus-within {
  border-color: var(--burn-ink);
}

.date-picker-btn svg {
  pointer-events: none;
}

.date-picker-btn input[type="date"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
  pointer-events: auto;
  -webkit-appearance: none;
  appearance: none;
  color-scheme: dark;
}

/* ---- accordion (hairline, not a boxed card -- keeps the panel calm) ---- */
.accordion {
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
}

.accordion > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 0;
  font-size: 14px;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  min-height: 44px;
}

.accordion > summary::-webkit-details-marker { display: none; }

.accordion .chevron {
  color: var(--ink-dim);
  font-size: 18px;
  transition: transform 0.2s ease;
}

.accordion[open] .chevron { transform: rotate(90deg); }

.accordion .field { padding: 0; }
.accordion .field:last-child { padding-bottom: 12px; }
.accordion > summary + .field { margin-top: 2px; }
.accordion .field + .field { margin-top: 12px; }

/* ---- toggle button groups: one unified iOS-style segmented control for
   every group (film preset / message style / placement / export format) ---- */
.toggle {
  display: flex;
  gap: 0;
  margin-top: 8px;
  padding: 2px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-dim);
}

.toggle button {
  flex: 1;
  background: transparent;
  color: var(--ink-dim);
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  min-height: 40px;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.toggle button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow-card);
  font-weight: 500;
}

/* ---- sliders ----
   Progress fill is mandatory (UI_SPEC.md §11.2): app.js keeps each range
   input's own `background` set to a two-stop linear-gradient (ink up to the
   current value, --border beyond). The track pseudo-elements are forced
   transparent so that gradient -- not an implicit fallback -- is what
   renders; padding/content-box-clip confines it to a slim 4px stripe while
   the input's full box stays a 44px-tall tap target. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  padding: 20px 0;
  background-clip: content-box;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: transparent;
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: transparent;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  cursor: pointer;
  margin-top: -8px;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  cursor: pointer;
}

/* ---- buttons ---- */
button {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: filter 0.15s ease;
  min-height: 44px;
  font-family: inherit;
}

button:active { transform: scale(0.98); }

button.primary {
  background: var(--ink-strong);
  color: #fff;
  border-color: var(--ink-strong);
}

button.primary:hover { filter: brightness(1.15); }

button.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--border);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.link-btn {
  flex: none;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 4px 0;
  color: var(--ink-dim);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  text-underline-offset: 2px;
  min-height: 44px;
}

.link-btn:hover,
.link-btn:focus-visible {
  color: var(--accent);
  text-decoration: underline;
}

/* ============ desktop / tablet ============ */
@media (min-width: 768px) {
  .welcome-inner { padding-top: 36px; }

  #editor {
    flex-direction: row;
    height: calc(100vh - 61px);
    height: calc(100dvh - 61px);
  }

  #stage { padding: 24px; }

  #panel {
    width: 340px;
    max-height: none;
    border-top: none;
    border-left: 1px solid var(--border);
    flex-shrink: 0;
  }

  #panel.collapsed { max-height: none; }

  .sheet-handle { display: none; }
}

/* ============ reduced motion ============ */
@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.001ms !important;
    animation-duration: 0.001ms !important;
  }
  .demo-print { opacity: 1; translate: 0 0; }
}
