/* 夕方の部屋: 暗い床の上に物が散らばる / 段ボールのクラフト色 / 業者の作業着のオレンジ / 判定は感熱紙のレシート */
:root {
  color-scheme: dark;
  --night: #24272b;
  --floor: #2f3337;
  --floor-line: #3a3f44;
  --ink: #f1eee8;
  --muted: #a3a8ad;
  --kraft: #b98b57;
  --kraft-dark: #8f6a40;
  --tape: rgba(232, 214, 168, .75);
  --orange: #ff7a1a;
  --paper: #f7f6f2;
  --thermal: #2a2a2a;
  --c-memory: #e6b85c;
  --c-practical: #8fb3c9;
  --c-vanity: #c995d6;
  --c-regret: #9db38a;
  --c-secret: #e07a6b;
  --c-body: #d9d2c5;
  --gothic: system-ui, -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --cell: 52px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  height: 100vh; height: 100dvh; overflow: hidden; overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--night); color: var(--ink); font-family: var(--gothic);
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
#app { position: relative; width: 100%; height: 100%; }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.screen[hidden] { display: none; }
.center { align-items: center; justify-content: center; gap: 1.1rem; padding: 1.5rem; text-align: center; overflow-y: auto; }
.muted { color: var(--muted); font-size: .9rem; }
.tiny { color: var(--muted); font-size: .8rem; font-family: var(--mono); letter-spacing: .08em; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 3px; }

.btn {
  min-height: 48px; min-width: 180px; padding: .75rem 1.6rem; border: 0; border-radius: 6px;
  font: inherit; font-weight: 700; letter-spacing: .06em; color: #1b1b1b; background: var(--orange);
  cursor: pointer; touch-action: manipulation; transition: filter .15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn.secondary { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px #5d6369; }
.btn.secondary:hover { background: #33383d; }
.icon-btn { width: 44px; height: 44px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); font-size: 1.3rem; cursor: pointer; touch-action: manipulation; }

/* ---- タイトル: 段ボールに養生テープ ---- */
.title-screen {
  background:
    linear-gradient(90deg, transparent 0 calc(50% - 60px), var(--tape) calc(50% - 60px) calc(50% + 60px), transparent calc(50% + 60px)),
    radial-gradient(ellipse at 50% 45%, #c79a64, var(--kraft-dark) 75%);
  color: #2a1d10;
}
.title-screen .eyebrow { font-weight: 700; letter-spacing: .25em; font-size: .85rem; }
.title { font-size: clamp(2.2rem, 7vw, 4.4rem); font-weight: 900; letter-spacing: .08em; transform: rotate(-2deg); text-shadow: 0 2px 0 rgba(255, 255, 255, .25); }
.title-screen .lead { font-weight: 600; }
.title-screen .btn.secondary { color: #2a1d10; box-shadow: inset 0 0 0 2px #2a1d10; }
.title-screen .btn.secondary:hover { background: rgba(255, 255, 255, .15); }
.title-screen .tiny { color: #3a2a18; }
.h2 { font-size: 1.4rem; letter-spacing: .15em; }
.gallery-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; width: min(100%, 420px); text-align: left; }
.gallery-list li { padding: .8rem 1rem; border: 1px solid #4a5056; border-radius: 6px; }
.gallery-list li.seen { border-color: var(--orange); }
.gallery-list .no { font-family: var(--mono); color: var(--orange); margin-right: .75rem; }

/* ---- プレイ ---- */
.hud { flex: none; height: 56px; display: flex; align-items: center; padding: 0 .5rem; gap: .5rem; }
.clock-wrap { flex: 1; display: flex; align-items: baseline; justify-content: center; gap: .75rem; }
.clock { font-family: var(--mono); font-size: 2rem; font-weight: 700; color: var(--orange); letter-spacing: .05em; }
.clock.hurry { animation: pulse 1s infinite; }
.clock-cap { font-size: .8rem; color: var(--muted); }
.call { min-width: 0; min-height: 40px; padding: .4rem .9rem; font-size: .85rem; background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1px #5d6369; }
.call:hover { background: #33383d; }
@media (max-width: 480px) { .clock-cap { display: none; } }
@keyframes pulse { 50% { opacity: .45; } }
.stage { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.world { position: absolute; left: 0; top: 0; width: 1440px; height: 720px; transform-origin: 0 0; }

.zone { position: absolute; }
.floor {
  left: 20px; top: 20px; width: calc(var(--cell) * 20); height: calc(var(--cell) * 13); border-radius: 4px;
  background-color: var(--floor);
  background-image: linear-gradient(var(--floor-line) 1px, transparent 1px), linear-gradient(90deg, var(--floor-line) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
}
.box {
  width: calc(var(--cell) * 6); height: calc(var(--cell) * 4);
  background-color: var(--kraft);
  background-image: linear-gradient(rgba(0, 0, 0, .12) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 0, 0, .12) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  box-shadow: 0 0 0 6px var(--kraft-dark), 0 14px 30px rgba(0, 0, 0, .35);
}
.zone-label { position: absolute; font-weight: 800; letter-spacing: .1em; font-size: 22px; color: var(--ink); }
.zone-label small { font-weight: 500; color: var(--muted); font-size: 16px; margin-left: .5em; font-family: var(--mono); }
.trash {
  width: calc(var(--cell) * 6); border-radius: 14px;
  background: #1a1c1f; border: 2px dashed #555b61; display: flex; flex-wrap: wrap; align-content: flex-start; gap: 4px; padding: 30px 8px 8px; overflow-y: auto; overscroll-behavior: contain;
}
.trash::before { content: "ゴミ袋（" attr(data-count) "）"; position: absolute; left: 12px; top: 6px; font-size: 16px; color: var(--muted); font-weight: 700; }
.trash.over, .zone.over { outline: 3px solid var(--orange); outline-offset: 4px; }
.chip { font: inherit; font-size: 13px; padding: 1px 6px; border-radius: 4px; background: #33383d; color: var(--ink); border: 0; cursor: pointer; min-height: 28px; }

.item { position: absolute; cursor: grab; touch-action: none; }
/* 小さい画面で押しやすいよう、当たり判定だけ周囲に広げる（見た目は変えない） */
@media (hover: none) { .item::after { content: ""; position: absolute; inset: -6px; } }
.item .cell {
  position: absolute; width: var(--cell); height: var(--cell);
  background: var(--paper); border: 1px solid rgba(0, 0, 0, .25);
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .08);
}
.item .label {
  position: absolute; left: 4px; top: 2px; right: 2px; font-size: 15px; line-height: 1.25; color: #222; font-weight: 700; pointer-events: none;
  display: flex; gap: 4px; align-items: flex-start;
}
.item .label .ic { font-size: 22px; line-height: 1; }
.item.one .label .nm { display: none; }
.item.one .label { justify-content: center; align-items: center; inset: 0; }
.item.one .label .ic { font-size: 28px; }
.item[data-cat="memory"] .cell { background: #f5e3bb; }
.item[data-cat="practical"] .cell { background: #dde8ef; }
.item[data-cat="vanity"] .cell { background: #ecdcf1; }
.item[data-cat="regret"] .cell { background: #e1e9d9; }
.item[data-cat="secret"] .cell { background: #f3d6d1; }
.item[data-cat="body"] .cell { background: var(--c-body); border: 1px dashed #7d7466; }
.item:hover .cell { filter: brightness(1.06); }
.item.glow .cell { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px var(--orange), 0 0 18px var(--orange); } }
.item.dragging { z-index: 20; cursor: grabbing; opacity: .92; }
.item.dragging .cell { box-shadow: 0 10px 24px rgba(0, 0, 0, .4); }
.item.ok .cell { outline: 3px solid #5fd38d; outline-offset: -3px; }
.item.ng .cell { outline: 3px solid #ff5a5a; outline-offset: -3px; }
.item.selected .cell { outline: 3px solid var(--orange); outline-offset: -3px; }
.item.new .cell { animation: appear .5s ease-out; }
@keyframes appear { from { transform: scale(.6); opacity: 0; } }

.hint-float {
  position: absolute; z-index: 15; padding: 6px 12px; border-radius: 6px; background: var(--orange); color: #1b1b1b; font-weight: 800; font-size: 18px;
  pointer-events: none; white-space: nowrap; animation: bob 1.2s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-6px); } }
.hint-rotate { left: 0; top: -44px; }

.timeskip {
  position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; opacity: 0;
  font-size: clamp(1.6rem, 5vw, 3rem); font-weight: 900; letter-spacing: .2em; color: var(--ink); background: rgba(10, 10, 12, .55);
}
.timeskip.show { animation: skip 1.1s ease-out; }
@keyframes skip { 0% { opacity: 0; } 20%, 70% { opacity: 1; } 100% { opacity: 0; } }

.subtitles { flex: none; height: 5.6rem; padding: .25rem 1rem .6rem; display: flex; flex-direction: column; justify-content: flex-end; gap: .15rem; overflow: hidden; }
.sub { font-size: .95rem; line-height: 1.55; color: var(--muted); }
.sub:last-child { color: var(--ink); font-size: 1.02rem; }

/* カード（PC: 横 / スマホ: 下から） */
.card {
  position: absolute; top: 64px; right: 1rem; width: min(380px, calc(100% - 2rem)); max-height: calc(100% - 80px); overflow-y: auto; z-index: 30;
  background: var(--paper); color: #222; border-radius: 10px; padding: 1rem 1.1rem 1.1rem; display: flex; flex-direction: column; gap: .75rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, .45);
}
.card[hidden] { display: none; }
.card.left { right: auto; left: 1rem; }
.card-head { display: flex; align-items: center; gap: .5rem; }
.card-head h3 { flex: 1; font-size: 1.1rem; }
.card-head .icon-btn { color: #222; }
.card-icon { font-size: 1.6rem; }
.card-look { line-height: 1.7; }
.card-result { white-space: pre-line; line-height: 1.8; padding: .75rem .9rem; background: #ece9e1; border-left: 4px solid var(--orange); border-radius: 4px; }
.card-actions, .card-moves { display: flex; flex-direction: column; gap: .45rem; }
.card-moves { flex-direction: row; flex-wrap: wrap; }
.card .btn { min-width: 0; width: 100%; text-align: left; }
.card .btn.secondary { color: #222; box-shadow: inset 0 0 0 1px #b9b5ab; }
.card .btn.secondary:hover { background: #ece9e1; }
.card-moves .btn { width: auto; flex: 1 1 45%; text-align: center; font-size: .9rem; padding: .6rem .5rem; }
.card .need { font-size: .8rem; color: #7a756b; }
@media (max-width: 760px), (max-height: 520px) {
  .card, .card.left { left: .5rem; right: .5rem; width: auto; top: auto; bottom: .5rem; max-height: 62%; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .card, .card.left { left: auto; right: .5rem; width: min(360px, 55%); top: .5rem; bottom: auto; max-height: calc(100% - 1rem); }
  .card.left { left: .5rem; right: auto; }
  .hud { height: 42px; }
  .clock { font-size: 1.4rem; }
  .subtitles { height: 3.2rem; }
  .sub { font-size: .8rem; }
  .sub:nth-last-child(n+3) { display: none; }
}

/* ---- 業者の到着・エンディング ---- */
.scene-screen { background: #141517; }
.scene { flex: 1; overflow-y: auto; width: min(100%, 760px); margin: 0 auto; padding: 2rem 1.25rem 1rem; display: flex; flex-direction: column; justify-content: flex-end; gap: .9rem; }
.line { line-height: 1.8; font-size: 1.1rem; animation: rise .35s ease-out; }
.line .who { display: inline-block; font-size: .75rem; font-weight: 800; padding: 1px 8px; margin-right: .6rem; border-radius: 3px; vertical-align: 2px; }
.line.mover1 .who, .line.mover2 .who { background: var(--orange); color: #1b1b1b; }
.line.you .who { background: var(--ink); color: #1b1b1b; }
.line.new .who { background: var(--c-body); color: #1b1b1b; }
.line.narr { color: var(--muted); }
.end-card { margin-top: 1.5rem; text-align: center; animation: rise .8s ease-out; }
.end-card .no { font-family: var(--mono); color: var(--orange); letter-spacing: .3em; }
.end-card .name { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 900; letter-spacing: .12em; margin-top: .4rem; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.scene-foot { flex: none; display: flex; justify-content: center; gap: .75rem; padding: 1rem 1rem 1.5rem; }

/* ---- 人生判定: 感熱紙の作業完了票 ---- */
.result-screen { overflow-y: auto; display: block; padding: 1.5rem 1rem 3rem; background: #1b1d20; -webkit-user-select: text; user-select: text; }
.again { position: fixed; top: calc(env(safe-area-inset-top) + .75rem); right: calc(env(safe-area-inset-right) + .75rem); z-index: 3; min-width: 0; }
.slip {
  width: min(100%, 440px); margin: 3rem auto 0; background: var(--paper); color: var(--thermal); padding: 1.6rem 1.4rem 2rem;
  font-family: var(--mono); font-size: .92rem; line-height: 1.75; position: relative;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
  -webkit-mask: radial-gradient(circle 7px at 50% 100%, transparent 6.5px, #000 7px) 0 0 / 18px 100% repeat-x;
          mask: radial-gradient(circle 7px at 50% 100%, transparent 6.5px, #000 7px) 0 0 / 18px 100% repeat-x;
  animation: print 1.1s steps(18) both;
}
@keyframes print { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0 0 0 0); } }
.slip h2 { text-align: center; font-size: 1.05rem; letter-spacing: .15em; }
.slip .center-t { text-align: center; }
.slip hr { border: 0; border-top: 2px dashed #9a9a9a; margin: .9rem 0; }
.slip .row { display: flex; justify-content: space-between; gap: 1rem; }
.slip .big { font-family: var(--gothic); font-weight: 800; font-size: 1.15rem; line-height: 1.6; margin: .3rem 0; }
.slip .prose { font-family: var(--gothic); line-height: 1.8; }
.slip ul { list-style: none; }
.slip li::before { content: "・"; }
.slip .strike { text-decoration: line-through; text-decoration-thickness: 2px; }
.slip li.strike::before { display: inline-block; text-decoration: none; }
.slip .truth { font-family: var(--gothic); font-weight: 800; color: #9b1c12; }
.slip .actions { display: flex; flex-direction: column; gap: .6rem; margin-top: 1.4rem; font-family: var(--gothic); }
.slip .btn.secondary { color: var(--thermal); box-shadow: inset 0 0 0 1px #8a8a8a; }
.slip .btn.secondary:hover { background: #ecebe6; }

/* ---- モーダル ---- */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: rgba(0, 0, 0, .6); backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.dialog { width: min(100%, 360px); max-height: 100%; overflow-y: auto; padding: 1.5rem; background: #2d3135; border-radius: 10px; text-align: center; display: flex; flex-direction: column; gap: 1rem; }
.dialog .actions { display: flex; flex-direction: column; gap: .75rem; }
.dialog .btn { width: 100%; }
#rotate { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
