/* ============================================================
   StorySlip by Storitellah — styles.css
   Mobile-first, receipt-inspired, print-friendly.
   ============================================================ */

:root {
  --paper: #faf7f0;
  --paper-deep: #f1ecdf;
  --ink: #1c1a16;
  --ink-soft: #5a554b;
  --line: #d9d2c0;
  --accent: #d4380d;
  --receipt-paper: #fffdf6;
  --shadow: 0 2px 10px rgba(30, 25, 10, 0.10);
  --radius: 10px;
  --mono: "Courier New", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --tap: 44px; /* minimum touch target */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(212, 56, 13, 0.045), transparent 40%),
    repeating-linear-gradient(0deg, transparent 0 34px, rgba(28, 26, 22, 0.025) 34px 35px),
    var(--paper);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  /* leave room for the fixed bottom bar on mobile */
  padding-bottom: calc(76px + var(--safe-bottom));
}

a { color: inherit; }

/* ---------------- Header ---------------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(250, 247, 240, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px dashed var(--line);
  padding-top: var(--safe-top);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { color: var(--ink); flex: none; }
.brand-title {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: 0.04em;
  font-family: var(--mono);
  text-transform: uppercase;
}
.brand-sub { margin: 0; font-size: 0.75rem; color: var(--ink-soft); }
.brand-sub a { color: var(--accent); text-decoration-thickness: 1px; }

.live-clock {
  text-align: right;
  font-family: var(--mono);
  line-height: 1.25;
  display: flex;
  flex-direction: column;
  flex: none;
}
.clock-date { font-size: 0.72rem; color: var(--ink-soft); }
.clock-time { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock-zone { font-size: 0.62rem; color: var(--ink-soft); letter-spacing: 0.03em; }

.tagline {
  max-width: 1100px;
  margin: 14px auto 0;
  padding: 0 16px;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------------- Layout ---------------- */

.layout {
  max-width: 1100px;
  margin: 14px auto 0;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 880px) {
  body { padding-bottom: 40px; }
  .layout { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  .preview-col { position: sticky; top: 86px; }
}

/* ---------------- Panels ---------------- */

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}

.panel-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.98rem;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.panel-summary::-webkit-details-marker { display: none; }
.panel-icon { color: var(--accent); width: 1.2em; text-align: center; }
.panel-chevron {
  margin-left: auto;
  width: 9px; height: 9px;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
details[open] > .panel-summary .panel-chevron { transform: rotate(-135deg); }

.count-pill {
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 2px 9px;
  font-family: var(--mono);
}

.panel-body { padding: 4px 16px 16px; border-top: 1px dashed var(--line); }

.panel-footer-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin-top: 8px;
  flex-wrap: wrap;
}

/* ---------------- Fields ---------------- */

.field { margin-top: 12px; min-width: 0; }
.field label, .field .label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 5px;
  letter-spacing: 0.02em;
}
.opt { color: var(--ink-soft); font-weight: 400; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .field-row { grid-template-columns: 1fr; gap: 0; } }

input[type="text"], input[type="date"], input[type="number"], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  font-size: 16px; /* prevents iOS zoom-on-focus */
  color: var(--ink);
  background: var(--receipt-paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 56, 13, 0.14);
}

.hint { font-size: 0.76rem; color: var(--ink-soft); margin: 6px 0 0; }
.hint.center { text-align: center; }

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; min-width: 0; }

/* ---------------- Buttons ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 16px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--ink); color: var(--receipt-paper); border-color: var(--ink); }
.btn-ghost { background: transparent; }
.btn-small { min-height: 38px; padding: 6px 12px; font-size: 0.82rem; }
.btn-danger { color: #a8271b; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* ---------------- Chips (radio / checkbox pills) ---------------- */

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--receipt-paper);
  font-size: 0.85rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.chip input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.chip:has(input:checked) {
  background: var(--ink);
  color: var(--receipt-paper);
  border-color: var(--ink);
}

.custom-width { max-width: 200px; }
.accent-picker { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.accent-picker label { margin: 0; font-size: 0.8rem; font-weight: 700; }
.accent-picker input[type="color"] {
  width: 54px; height: 40px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--receipt-paper);
  cursor: pointer;
}

/* ---------------- Caption list ---------------- */

.caption-list { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 10px; }

.caption-item {
  display: grid;
  grid-template-columns: 28px 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  background: var(--receipt-paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  transition: box-shadow 0.15s ease, opacity 0.15s ease;
}
.caption-item.dragging { opacity: 0.45; }
.caption-item.drag-over { box-shadow: 0 0 0 2px var(--accent); }
.caption-item.img-drop { box-shadow: 0 0 0 2px #2b7a2b; }

.drag-handle {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 1.05rem;
  cursor: grab;
  touch-action: none;
  border: none;
  background: none;
  padding: 0;
  min-width: 28px;
}
.drag-handle:active { cursor: grabbing; }

.thumb-slot {
  width: 64px;
  height: 64px;
  border: 1.5px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
  position: relative;
  padding: 0;
  font-size: 1.3rem;
  color: var(--ink-soft);
  -webkit-tap-highlight-color: transparent;
}
.thumb-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-slot .thumb-x {
  position: absolute;
  top: 2px; right: 2px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(20, 18, 14, 0.78);
  color: #fff;
  font-size: 0.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.caption-fields { display: grid; gap: 6px; min-width: 0; }
.caption-fields textarea {
  min-height: 44px;
  padding: 8px 10px;
  font-size: 16px;
}
.caption-time-row { display: flex; align-items: center; gap: 6px; }
.caption-time-row input {
  min-height: 36px;
  padding: 5px 9px;
  font-size: 14px;
  max-width: 130px;
  font-family: var(--mono);
}
.caption-time-row .tlabel { font-size: 0.72rem; color: var(--ink-soft); }

.caption-tools { display: flex; flex-direction: column; gap: 4px; }
.caption-tools button {
  width: 34px; height: 34px;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.caption-tools button:disabled { opacity: 0.3; cursor: not-allowed; }

.caption-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.drop-hint {
  margin-top: 12px;
  padding: 18px;
  text-align: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-weight: 700;
  background: rgba(212, 56, 13, 0.05);
}

@media (max-width: 420px) {
  .caption-item { grid-template-columns: 24px 56px minmax(0, 1fr) auto; gap: 7px; }
  .thumb-slot { width: 56px; height: 56px; }
}

/* ---------------- Preview column ---------------- */

.preview-col {
  background: var(--paper-deep);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.preview-head { display: flex; align-items: baseline; justify-content: space-between; }
.preview-title { margin: 0; font-size: 1rem; font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.06em; }
.preview-size { font-family: var(--mono); font-size: 0.78rem; color: var(--ink-soft); }

.preview-scroll {
  margin-top: 12px;
  max-height: 62vh;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 14px 6px;
  background:
    repeating-linear-gradient(45deg, rgba(28,26,22,0.03) 0 8px, transparent 8px 16px),
    #e7e1d1;
  border-radius: 8px;
  -webkit-overflow-scrolling: touch;
}

.receipt-shell {
  filter: drop-shadow(0 6px 14px rgba(25, 20, 8, 0.25));
  align-self: flex-start;
}
#receipt-canvas {
  display: block;
  /* torn receipt edges */
  clip-path: polygon(
    0 6px, 3% 0, 6% 6px, 9% 0, 12% 6px, 15% 0, 18% 6px, 21% 0, 24% 6px, 27% 0,
    30% 6px, 33% 0, 36% 6px, 39% 0, 42% 6px, 45% 0, 48% 6px, 51% 0, 54% 6px, 57% 0,
    60% 6px, 63% 0, 66% 6px, 69% 0, 72% 6px, 75% 0, 78% 6px, 81% 0, 84% 6px, 87% 0,
    90% 6px, 93% 0, 96% 6px, 100% 0,
    100% calc(100% - 6px), 97% 100%, 94% calc(100% - 6px), 91% 100%, 88% calc(100% - 6px), 85% 100%,
    82% calc(100% - 6px), 79% 100%, 76% calc(100% - 6px), 73% 100%, 70% calc(100% - 6px), 67% 100%,
    64% calc(100% - 6px), 61% 100%, 58% calc(100% - 6px), 55% 100%, 52% calc(100% - 6px), 49% 100%,
    46% calc(100% - 6px), 43% 100%, 40% calc(100% - 6px), 37% 100%, 34% calc(100% - 6px), 31% 100%,
    28% calc(100% - 6px), 25% 100%, 22% calc(100% - 6px), 19% 100%, 16% calc(100% - 6px), 13% 100%,
    10% calc(100% - 6px), 7% 100%, 4% calc(100% - 6px), 0 100%
  );
}

.export-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.export-row .btn { flex: 1; min-width: 110px; }

/* ---------------- Support section ---------------- */

.support {
  max-width: 1100px;
  margin: 34px auto 0;
  padding: 0 16px;
}
.support h2 { font-family: var(--mono); text-transform: uppercase; letter-spacing: 0.06em; font-size: 1.05rem; margin: 0 0 6px; }
.support > p { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 14px; }

.support-links { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .support-links { grid-template-columns: repeat(3, 1fr); } }

.support-card {
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  text-align: left;
  padding: 12px 14px;
  min-height: var(--tap);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.support-card:hover { border-color: var(--accent); }
.support-icon {
  grid-row: 1 / 3;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  background: var(--paper-deep);
  border-radius: 50%;
  font-size: 1.1rem;
}
.support-name { font-weight: 800; font-size: 0.92rem; }
.support-detail { font-size: 0.78rem; color: var(--ink-soft); font-family: var(--mono); overflow-wrap: anywhere; }

/* ---------------- Footer ---------------- */

.app-footer {
  max-width: 1100px;
  margin: 34px auto 0;
  padding: 18px 16px 8px;
  border-top: 1px dashed var(--line);
  text-align: center;
  font-size: 0.9rem;
}
.app-footer a { color: var(--accent); }
.footer-fine { color: var(--ink-soft); font-size: 0.75rem; }

/* ---------------- Bottom bar (mobile) ---------------- */

.bottom-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  background: rgba(255, 253, 246, 0.96);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding: 6px calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom)) calc(8px + var(--safe-left));
}
.bar-btn {
  flex: 1;
  min-height: 52px;
  border: none;
  background: none;
  font: inherit;
  font-size: 1.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  border-radius: 10px;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
.bar-btn span { font-size: 0.64rem; font-weight: 700; letter-spacing: 0.03em; }
.bar-btn:active { background: var(--paper-deep); }

/* the bottom bar is mobile-only; desktop has the export row in the preview panel */
@media (min-width: 880px) {
  .bottom-bar { display: none; }
}

/* ---------------- Toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(88px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 60;
  background: var(--ink);
  color: var(--receipt-paper);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  max-width: min(90vw, 420px);
  text-align: center;
}
@media (min-width: 880px) { .toast { bottom: 32px; } }

/* ---------------- Print ---------------- */

#print-area { display: none; }

@media print {
  body { background: #fff; padding: 0; }
  .app-header, .tagline, .layout, .support, .app-footer, .bottom-bar, .toast { display: none !important; }
  #print-area { display: block; }
  #print-area img { display: block; margin: 0 auto; }
}

/* ---------------- Reduced motion ---------------- */

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
