/* One-screen tool: header, picture, controls. Single dark look by choice. */
:root {
  color-scheme: dark;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  --bg: #0b1a24; --panel: #12283a; --line: #24465f; --text: #e8f1f6;
  --muted: #9bb4c4; --accent: #2bb3c0; --accent-text: #04222a;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { height: 100%; background: var(--bg); }
body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}
header, footer, #status {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
header, footer { background: var(--panel); padding-block: 10px; }
header { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
footer { border-top: 1px solid var(--line); display: grid; gap: 10px; }
h1 { font-size: 18px; margin: 0; letter-spacing: .02em; }
main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#stage { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; overflow: hidden; }
/* The canvas is the live render; the <img> on top of it is the same picture
   as a real image, because iOS only offers "Save to Photos" on images. */
#canvas, #preview { grid-area: 1 / 1; max-width: 100%; max-height: 100%; touch-action: none;
  transform-origin: center; -webkit-user-select: none; user-select: none; }
#canvas { -webkit-touch-callout: none; }
#preview { -webkit-touch-callout: default; -webkit-user-drag: none; }
#stage.empty #canvas, #stage.empty #preview { display: none; }
#hint { color: var(--muted); text-align: center; padding: 0 24px; }
#stage:not(.empty) #hint { display: none; }
#busy { position: absolute; inset: auto 0 16px 0; margin: auto; width: max-content; max-width: 90%;
  background: rgba(8, 20, 28, .85); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px; display: flex; gap: 10px; align-items: center; }
#busy[hidden] { display: none; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line);
  border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
#status { margin: 0; padding-block: 6px; min-height: 2.2em; color: var(--muted); font-size: 13px; }
#status.error { color: #ffb4a8; }
.row { display: flex; align-items: center; gap: 10px; }
.row > input[type=range] { flex: 1; accent-color: var(--accent); min-height: 32px; }
#params { flex: 1; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
#amountOut { width: 3.5em; text-align: right; font-variant-numeric: tabular-nums; }
.btn, .seg { font: inherit; color: var(--text); background: transparent; border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; min-height: 44px; cursor: pointer; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: .5; }
.seg { flex: 1; padding: 9px 4px; font-size: 14px; }
.seg.on { background: var(--line); border-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#saveHint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; }
#member { color: var(--muted); font-size: 13px; margin-left: auto; margin-right: 10px; white-space: nowrap; }
.link { font: inherit; font-size: 13px; color: var(--accent); background: none; border: 0; padding: 8px 4px;
  min-height: 36px; text-decoration: underline; cursor: pointer; }
#gate { position: fixed; inset: 0; z-index: 30; background: var(--bg); overflow-y: auto; display: grid; place-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 16px) max(16px, env(safe-area-inset-right, 0px))
           calc(env(safe-area-inset-bottom, 0px) + 16px) max(16px, env(safe-area-inset-left, 0px)); }
#gate .card { width: 100%; max-width: 26rem; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px; }
#gate h2 { margin: 0 0 12px; font-size: 20px; }
#gate form { display: grid; gap: 8px; }
#gate p { margin: 0 0 6px; }
#gate label { font-size: 14px; color: var(--muted); margin-top: 6px; }
#gate input { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
#gateCode { font-size: 24px; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }
#gate .fine { font-size: 13px; color: var(--muted); }
#gate .btn { margin-top: 8px; }
#gate .row { justify-content: space-between; }
#gateMsg { min-height: 1.5em; margin-top: 12px; font-size: 14px; color: var(--muted); }
#gateMsg.error { color: #ffb4a8; }
