/* 現場日報 demo — "工事黒板" (construction blackboard) visual language.
   Tokens: chalkboard green, chalk white, safety orange for the one action that matters. */
:root {
  --board: #1e3d33;
  --board-deep: #16302a;
  --board-edge: #0f231e;
  --chalk: #f4f1e8;
  --chalk-70: rgba(244, 241, 232, 0.7);
  --chalk-45: rgba(244, 241, 232, 0.45);
  --chalk-line: rgba(244, 241, 232, 0.28);
  --chalk-fill: rgba(244, 241, 232, 0.07);
  --orange: #ff6a13;
  --orange-deep: #d9540b;
  --ground: #edf0ea;
  --ink: #1b2a26;
  --ink-60: rgba(27, 42, 38, 0.6);
  --tape: #ffd23f;
  /* Chalk handwriting only for Japanese: Yusei Magic has no Vietnamese/Chinese glyphs. */
  --font-display: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 18px;
  --shadow: 0 18px 40px rgba(10, 30, 24, 0.35);
}

html[lang="ja"] { --font-display: "Yusei Magic", "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif; }
html:not([lang="ja"]) .ask, html:not([lang="ja"]) .card-label { font-weight: 700; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.app {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--chalk);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }

/* The phone column. On a desktop window it sits centered like a handset. */
.phone {
  position: relative;
  margin: 0 auto;
  max-width: 460px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 60% at 50% 0%, rgba(255, 255, 255, 0.06), transparent 60%),
    radial-gradient(80% 40% at 80% 100%, rgba(0, 0, 0, 0.18), transparent 70%),
    var(--board);
  box-shadow: 0 0 0 1px var(--board-edge), var(--shadow);
}
@media (min-width: 520px) {
  body.app { padding: 24px 16px; }
  .phone {
    min-height: calc(100vh - 48px);
    min-height: calc(100dvh - 48px);
    border-radius: 34px;
    overflow: hidden;
  }
}

/* Header */
.top {
  position: relative;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  background: var(--board-deep);
}
.top-title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.top-title .title { font-family: var(--font-display); font-size: 17px; letter-spacing: 0.02em; }
.top-title .step { font-size: 12px; color: var(--chalk-45); font-variant-numeric: tabular-nums; }
.icon-btn {
  height: 40px; min-width: 40px; padding: 0 10px;
  border: 1px solid var(--chalk-line); border-radius: 12px;
  background: var(--chalk-fill); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 15px;
}
.icon-btn:active { transform: scale(0.96); }
.icon-btn[hidden] { display: inline-flex; visibility: hidden; } /* keep the header grid stable */
.icon-btn .code { font-size: 12px; letter-spacing: 0.08em; color: var(--chalk-70); }
.progress {
  grid-column: 1 / -1;
  height: 3px; border-radius: 3px; margin-top: 8px;
  background: var(--chalk-line); overflow: hidden;
}
.progress i {
  display: block; height: 100%; width: 0;
  background: var(--orange);
  transition: width 0.35s ease;
}

/* Stage */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 18px 18px 12px;
  min-height: 0;
}
.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; animation: enter 0.28s ease both; }
@keyframes enter { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: none; } }
.screen.enter-back { animation-name: enter-back; }
@keyframes enter-back { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: none; } }

.eyebrow {
  margin: 0 0 4px; font-size: 12px; letter-spacing: 0.14em; color: var(--chalk-45);
  font-variant-numeric: tabular-nums;
}
.ask {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(24px, 6.4vw, 30px);
  line-height: 1.3;
  letter-spacing: 0.01em;
}
.sub { margin: 0 0 10px; font-size: 14px; color: var(--chalk-70); }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--chalk-45); text-align: center; }

/* Card deck */
.deck {
  position: relative;
  flex: 1;
  min-height: 240px;
  max-height: 44vh;
  margin: 10px 0 34px; /* room for the stacked cards peeking out below */
}
.card {
  position: absolute; inset: 0;
  border: 2px solid var(--chalk-line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    var(--board);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 22px;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transform-origin: 50% 110%;
  will-change: transform;
}
.card.back1 { transform: translateY(14px) scale(0.95); opacity: 0.75; }
.card.back2 { transform: translateY(28px) scale(0.9); opacity: 0.45; }
.card.top { touch-action: none; cursor: grab; transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
.card.top.dragging { transition: none; cursor: grabbing; }
.card.top.fly-right { transform: translate(130%, -8%) rotate(24deg) !important; opacity: 0; transition: transform 0.36s ease-in, opacity 0.36s ease-in; }
.card.top.fly-left { transform: translate(-130%, -8%) rotate(-24deg) !important; opacity: 0; transition: transform 0.36s ease-in, opacity 0.36s ease-in; }
.card-icon { font-size: 62px; line-height: 1; margin-bottom: 14px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3)); }
.card-label { font-family: var(--font-display); font-size: clamp(22px, 6vw, 28px); line-height: 1.4; overflow-wrap: anywhere; max-width: 100%; }
.card-label.small { font-size: clamp(19px, 5.2vw, 24px); }
.card-hint {
  position: absolute; left: 0; right: 0; bottom: 12px;
  display: flex; justify-content: space-between; padding: 0 16px;
  font-size: 12px; color: var(--chalk-45); letter-spacing: 0.04em;
}
.card-count { position: absolute; top: 12px; right: 14px; font-size: 12px; color: var(--chalk-45); font-variant-numeric: tabular-nums; }
.stamp {
  position: absolute; top: 18px;
  padding: 6px 12px; border: 3px solid; border-radius: 8px;
  font-family: var(--font-display); font-size: 20px; letter-spacing: 0.06em;
  opacity: 0; transform: rotate(-12deg);
  pointer-events: none;
}
.stamp.yes { left: 16px; color: var(--orange); border-color: var(--orange); }
.stamp.no { right: 16px; color: var(--chalk); border-color: var(--chalk); transform: rotate(12deg); }
.card.top.lean-right { border-color: var(--orange); box-shadow: 0 10px 30px rgba(255, 106, 19, 0.25); }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.chip {
  padding: 8px 12px; border-radius: 999px;
  border: 1px solid var(--chalk-line); background: transparent;
  font-size: 13.5px; cursor: pointer; white-space: normal; text-align: left; line-height: 1.3;
  transition: background 0.15s, border-color 0.15s;
}
.chip:active { transform: scale(0.97); }
.chip.on { background: var(--orange); border-color: var(--orange); color: #1b1410; font-weight: 700; }
.chip.on::before { content: "✔ "; }

/* Actions */
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: auto; padding-top: 12px; }
.actions.one { grid-template-columns: 1fr; }
.btn {
  height: 54px; border-radius: 16px; border: 2px solid var(--chalk-line);
  background: var(--chalk-fill); cursor: pointer;
  font-size: 17px; font-weight: 700; letter-spacing: 0.02em;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn.primary { background: var(--orange); border-color: var(--orange); color: #1b1410; box-shadow: 0 8px 20px rgba(255, 106, 19, 0.3); }
.btn.primary:disabled { opacity: 0.45; box-shadow: none; cursor: not-allowed; }
.btn.ghost { background: transparent; }
.btn.link { border: 0; background: transparent; color: var(--chalk-70); text-decoration: underline; text-underline-offset: 4px; font-weight: 500; height: 44px; }

/* Inputs */
.field {
  width: 100%; min-height: 120px; resize: none;
  padding: 14px; border-radius: 14px;
  border: 2px solid var(--chalk-line); background: var(--chalk-fill);
  color: var(--chalk); font: inherit; font-size: 18px; line-height: 1.5;
  outline: none;
}
.field:focus { border-color: var(--orange); }
.field::placeholder { color: var(--chalk-45); }
input.field { min-height: 0; height: 58px; }
input.field[type="date"] { color-scheme: dark; }
.field-error { margin: 8px 0 0; color: var(--tape); font-size: 14px; min-height: 20px; }

.stepper { display: grid; grid-template-columns: 72px 1fr 72px; align-items: center; gap: 10px; margin: auto 0; padding: 24px 0; }
.stepper button {
  height: 72px; border-radius: 20px; border: 2px solid var(--chalk-line); background: var(--chalk-fill);
  font-size: 34px; cursor: pointer;
}
.stepper button:active { transform: scale(0.96); }
.stepper .value { text-align: center; font-family: var(--font-display); font-size: 64px; line-height: 1; font-variant-numeric: tabular-nums; }
.stepper .unit { display: block; font-family: var(--font-body); font-size: 15px; color: var(--chalk-70); margin-top: 8px; }

/* Language screen */
.lang-list { display: grid; gap: 10px; margin-top: 8px; }
.lang-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-radius: 16px;
  border: 2px solid var(--chalk-line); background: var(--chalk-fill);
  font-size: 19px; cursor: pointer; text-align: left;
}
.lang-item .code { font-size: 12px; letter-spacing: 0.14em; color: var(--chalk-45); }
.lang-item.on { border-color: var(--orange); }
.lang-item:active { transform: scale(0.99); }

/* Confirm: the finished blackboard */
.blackboard {
  border: 2px solid var(--chalk-70);
  border-radius: 10px;
  overflow: hidden;
  margin: 6px 0 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent), var(--board-deep);
}
.bb-row {
  display: grid; grid-template-columns: 96px 1fr;
  border-top: 1px solid var(--chalk-line);
  cursor: pointer; background: transparent; border-left: 0; border-right: 0; border-bottom: 0;
  width: 100%; text-align: left; padding: 0;
}
.bb-row:first-child { border-top: 0; }
.bb-row:active { background: rgba(255, 255, 255, 0.05); }
.bb-row .k { padding: 8px 10px; font-size: 12px; color: var(--chalk-70); border-right: 1px solid var(--chalk-line); letter-spacing: 0.04em; }
.bb-row .v { padding: 7px 12px; font-family: var(--font-display); font-size: 16px; line-height: 1.35; word-break: break-word; }
.bb-row .v.muted { color: var(--chalk-45); font-family: var(--font-body); font-size: 14px; }

/* Done */
.done { align-items: center; justify-content: center; text-align: center; }
.done .mark {
  width: 110px; height: 110px; border-radius: 50%;
  border: 4px solid var(--orange); display: grid; place-items: center;
  font-size: 56px; color: var(--orange); margin-bottom: 18px;
  animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }
.done h1 { margin: 0 0 6px; }
.done .no { margin: 14px 0 22px; font-size: 14px; color: var(--chalk-70); }
.done .no b { font-family: var(--font-display); font-size: 26px; color: var(--chalk); letter-spacing: 0.12em; display: block; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  padding: 10px 16px; border-radius: 12px;
  background: var(--chalk); color: var(--ink); font-size: 14px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: 90vw; text-align: center; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.foot {
  padding: 6px 12px max(10px, env(safe-area-inset-bottom));
  text-align: center; font-size: 11px; color: var(--chalk-45); letter-spacing: 0.06em;
}

/* Focus & motion */
:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  .screen, .done .mark { animation: none; }
  .card.top { transition: none; }
  .card.top.fly-right, .card.top.fly-left { transition: opacity 0.1s; transform: none !important; }
  .progress i { transition: none; }
}
