:root {
  --bg: #0b0e1a;
  --bg2: #141a2e;
  --card: #1a2140;
  --card-border: #2a3358;
  --text: #eef1ff;
  --muted: #9aa3c7;
  --accent: #7dd3fc;
  --accent2: #f472b6;
  --danger: #f87171;
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: radial-gradient(1200px 600px at 50% -10%, #223064 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}
a { color: var(--accent); }

/* ---------- 建立頁 ---------- */
.page {
  max-width: 560px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  padding-top: calc(24px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px));
}
header.hero { text-align: center; margin-bottom: 24px; }
header.hero h1 { font-size: 2rem; margin: 0 0 6px; letter-spacing: .02em; }
header.hero p { color: var(--muted); margin: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25);
}
.card h2 { font-size: 1.1rem; margin: 0 0 4px; }
.card .hint { color: var(--muted); font-size: .9rem; margin: 0 0 12px; }

.drop {
  display: flex; align-items: center; justify-content: center;
  position: relative;
  min-height: 160px;
  border: 2px dashed #46528a;
  border-radius: 12px;
  background: rgba(255, 255, 255, .03);
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.dragging { border-color: var(--accent); background: rgba(125, 211, 252, .08); }
.drop.has-image { border-style: solid; }
.drop img.preview { max-height: 260px; width: 100%; object-fit: contain; display: block; background: #000; }
.drop .placeholder {
  color: var(--muted); font-size: 1rem; padding: 12px; text-align: center;
}
.drop.has-image .placeholder {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: .85rem; padding: 6px;
}

.choices { display: flex; gap: 8px; flex-wrap: wrap; }
.choices label {
  flex: 1 1 0; min-width: 90px;
  text-align: center; padding: 10px 8px;
  border: 1px solid var(--card-border); border-radius: 10px;
  cursor: pointer; user-select: none;
}
.choices input { display: none; }
.choices label:has(input:checked) { border-color: var(--accent); background: rgba(125, 211, 252, .12); color: #fff; }
.choices label small { display: block; color: var(--muted); font-size: .78rem; }

button, .button {
  appearance: none; -webkit-appearance: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: #232c50; color: var(--text);
  cursor: pointer; text-decoration: none;
  transition: transform .05s, filter .15s;
}
button:hover, .button:hover { filter: brightness(1.15); }
button:active, .button:active { transform: scale(.98); }
button:disabled { opacity: .45; cursor: not-allowed; filter: none; transform: none; }
.primary { background: linear-gradient(135deg, #38bdf8, #818cf8); color: #0b0e1a; border-color: transparent; }
.block { width: 100%; font-size: 1.05rem; padding: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions > * { flex: 1 1 auto; }

.status { min-height: 1.5em; color: var(--muted); text-align: center; margin: 10px 0; }
.status.error { color: var(--danger); }

.linkbox input {
  width: 100%; font: inherit; font-size: .9rem;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--card-border); background: #0f1430; color: var(--text);
}
.note { color: var(--muted); font-size: .85rem; margin: 10px 0 0; }
footer.foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 24px; }

/* ---------- 遊玩頁 ---------- */
body.play {
  position: fixed; inset: 0; width: 100%;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
  overflow: hidden;
  overscroll-behavior: none;
}
/* 遊戲頁整頁禁止選取文字、長按選單、拖曳，避免手指滑出畫布時觸發 Safari 的功能 */
body.play, body.play * {
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body.play .panel .msg { -webkit-user-select: text; user-select: text; }
body.play .allow-native { -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
#photoOverlay { position: absolute; z-index: 5; object-fit: fill; border-radius: 2px; cursor: context-menu; }
.panel .tiny { font-size: .78rem; color: var(--muted); margin-top: -2px; }
.panel .wincount { color: #fbbf24; font-weight: 600; font-size: .95rem; }
.panel ul.howto { text-align: left; margin: 8px 0 4px; padding-left: 20px; color: var(--text); font-size: .92rem; line-height: 1.55; }
.panel ul.howto li { margin: 4px 0; }
.panel .lockhint { color: #fde68a; background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.3); border-radius: 10px; padding: 8px 10px; font-size: .9rem; }
.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 10px 12px; border: 1px solid var(--card-border); border-radius: 10px; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.check small { display: block; color: var(--muted); font-size: .82rem; }
.field { margin-top: 12px; }
.opt.req { color: #fca5a5; border-color: rgba(252,165,165,.4); }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; }
.field input { width: 100%; font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--card-border); background: #0f1430; color: var(--text); }
.field input:focus { outline: none; border-color: var(--accent); }
.panel input.pw { width: 100%; font: inherit; font-size: 1rem; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--card-border); background: #0f1430; color: var(--text); margin: 8px 0 4px; -webkit-user-select: text; user-select: text; }
.topbar .right { display: flex; gap: 6px; }
.topbar a.small.danger, .topbar button.small { font-size: .85rem; font-weight: 600; padding: 5px 10px; border-radius: 999px; }
body.play .topbar a { touch-action: manipulation; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  font-weight: 700; flex: 0 0 auto;
}
.topbar .brand { color: #fff; }
.topbar a.small { font-size: .85rem; font-weight: 600; text-decoration: none;
  border: 1px solid var(--card-border); padding: 5px 10px; border-radius: 999px; }
#stage {
  position: relative; flex: 1 1 auto; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px calc(6px + env(safe-area-inset-bottom, 0px));
}
#game {
  display: block;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
  touch-action: none;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  cursor: crosshair;
}
.overlay {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  pointer-events: none;
}
.overlay[hidden] { display: none; }
.panel {
  pointer-events: auto;
  width: 100%; max-width: 380px;
  background: rgba(20, 26, 46, .94);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
  backdrop-filter: blur(8px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
.panel h2 { margin: 0 0 6px; font-size: 1.3rem; }
.panel p { margin: 0 0 4px; color: var(--muted); font-size: .92rem; }
.panel .actions { margin-top: 10px; }
.panel .actions button, .panel .actions .button { padding: 10px 12px; }

/* 留言 */
.card h2 small.opt { font-size: .75rem; font-weight: 500; color: var(--muted); border: 1px solid var(--card-border); border-radius: 999px; padding: 1px 8px; vertical-align: middle; margin-left: 4px; }
textarea#message {
  width: 100%; font: inherit; font-size: 1rem; line-height: 1.5;
  padding: 10px 12px; border-radius: 10px; resize: vertical; min-height: 72px;
  border: 1px solid var(--card-border); background: #0f1430; color: var(--text);
}
textarea#message:focus { outline: none; border-color: var(--accent); }
.counter { text-align: right; color: var(--muted); font-size: .8rem; margin-top: 4px; }
.panel .msg {
  margin: 8px 0 10px; padding: 10px 12px;
  background: rgba(125, 211, 252, .08); border: 1px solid rgba(125, 211, 252, .35);
  border-radius: 12px; color: #fff; font-size: 1.05rem; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; text-align: center;
}
.panel .msg::before { content: '💬 '; }

/* ---------- 裁切器 ---------- */
body.crop-open { overflow: hidden; }
.crop-modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(5, 8, 20, .85);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.crop-dialog {
  width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  padding: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.6);
  display: flex; flex-direction: column; gap: 10px;
  max-height: 100%;
}
.crop-title { display: flex; flex-direction: column; gap: 2px; }
.crop-title strong { font-size: 1.05rem; }
.crop-title span { color: var(--muted); font-size: .8rem; }
.crop-frame {
  position: relative; width: 100%; overflow: hidden;
  background: #000; border-radius: 10px;
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
  margin: 0 auto;
}
.crop-frame:active { cursor: grabbing; }
.crop-frame canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; pointer-events: none; }
.crop-frame::after {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.85);
  background:
    linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255,255,255,.25) calc(33.33% - .5px), rgba(255,255,255,.25) calc(33.33% + .5px), transparent calc(33.33% + .5px)),
    linear-gradient(to right, transparent calc(66.66% - .5px), rgba(255,255,255,.25) calc(66.66% - .5px), rgba(255,255,255,.25) calc(66.66% + .5px), transparent calc(66.66% + .5px)),
    linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255,255,255,.25) calc(33.33% - .5px), rgba(255,255,255,.25) calc(33.33% + .5px), transparent calc(33.33% + .5px)),
    linear-gradient(to bottom, transparent calc(66.66% - .5px), rgba(255,255,255,.25) calc(66.66% - .5px), rgba(255,255,255,.25) calc(66.66% + .5px), transparent calc(66.66% + .5px));
}
.crop-zoom { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.crop-zoom input { flex: 1; accent-color: var(--accent); }
.crop-actions { display: flex; gap: 8px; }
.crop-actions button { flex: 1; }

/* 4:5 預覽框與重新裁切按鈕 */
.drop-wrap { position: relative; }
.drop-wrap.has-image { max-width: 300px; margin: 0 auto; }
.drop.has-image { aspect-ratio: 4 / 5; min-height: 0; }
.drop.has-image img.preview { width: 100%; height: 100%; max-height: none; object-fit: cover; }
.drop-wrap .recrop {
  position: absolute; top: 8px; right: 8px; display: none; z-index: 2;
  padding: 6px 10px; font-size: .8rem; border-radius: 999px;
  background: rgba(0,0,0,.65); border-color: rgba(255,255,255,.35); color: #fff;
}
.drop-wrap.has-image .recrop { display: inline-flex; }

/* 分享選單（桌機） */
.share-menu {
  position: fixed; z-index: 2000; min-width: 190px;
  background: #1a2140; border: 1px solid var(--card-border); border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); padding: 6px; display: flex; flex-direction: column; gap: 2px;
}
.share-menu button {
  justify-content: flex-start; width: 100%; padding: 10px 12px; border: 0; border-radius: 8px;
  background: transparent; font-weight: 500; font-size: .95rem;
}
.share-menu button:hover { background: rgba(255,255,255,.08); filter: none; }

/* 語言切換 */
.langbtn { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; padding: 6px 12px; font-size: .85rem; border-radius: 999px; }
.page { position: relative; }
.topbar button.small { background: transparent; border: 1px solid var(--card-border); color: var(--accent); }
.topbar button.small.danger { color: #fecaca; border-color: #7f1d1d; background: #3b1a22; }

/* 遊戲頁上方列：手機上不換行 */
.topbar { gap: 8px; }
.topbar .brand { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .right { flex: 0 0 auto; flex-wrap: nowrap; }
.topbar .small { white-space: nowrap; }
@media (max-width: 520px) {
  .topbar .brand { display: none; }
  .topbar { justify-content: flex-end; }
}
