:root {
  --bg: #140f24;
  --panel: #221a3a;
  --panel-2: #2e2550;
  --line: #3d3366;
  --text: #ece8f7;
  --muted: #a59cc4;
  --accent: #a78bfa;
  --accent-2: #7c3aed;
  --warn: #f59e0b;
  --err: #f87171;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }

[hidden] { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: .6rem;
  padding: calc(env(safe-area-inset-top) + .7rem) 1rem .7rem;
  background: #0e0a1a; border-bottom: 1px solid #2a2245;
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 1.05rem; margin: 0; letter-spacing: .02em; }
.badge { font-size: .7rem; padding: .1rem .5rem; border-radius: 99px; background: #3b2470; color: #ddd6fe; }

main { max-width: 720px; margin: 0 auto; padding: 1rem; }

.lead { color: var(--muted); text-align: center; margin: .6rem 0 1.2rem; }
.lead b { color: var(--text); }
.note { color: var(--muted); font-size: .85rem; }
.note.center { text-align: center; margin: .4rem 0 .8rem; }

.step { display: flex; align-items: center; gap: .55rem; font-size: 1rem; margin: 1.4rem 0 .6rem; }
.step span {
  display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--accent-2); color: #fff; font-size: .85rem;
}
.step:first-child { margin-top: .2rem; }

.home-buttons { display: grid; gap: 1rem; }

.big-btn {
  display: flex; align-items: center; justify-content: center; gap: .8rem;
  min-height: 56px; padding: .9rem 1.2rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text);
  font-size: 1.05rem; font-weight: 600; cursor: pointer;
  touch-action: manipulation; font-family: inherit;
}
.big-btn:active { transform: scale(.98); }
.big-btn:disabled { opacity: .4; cursor: default; }
.big-btn.primary { background: var(--accent-2); border-color: var(--accent); color: #fff; }
.big-btn.wide { width: 100%; }
.home-buttons .big-btn, .file-btn { justify-content: flex-start; text-align: left; }
.home-buttons .big-btn { min-height: 92px; }
.big-btn .icon { font-size: 2rem; }
.big-btn small { display: block; font-weight: 400; font-size: .85rem; opacity: .85; }
.big-btn b { word-break: break-all; }
.file-btn input { display: none; }
#embed-btn, #extract-btn { margin-top: 1.4rem; min-height: 60px; font-size: 1.15rem; }

.back-btn { margin-top: 1.2rem; background: none; border: none; color: var(--muted); font-size: 1rem; padding: .6rem 0; cursor: pointer; }

.howto { margin-top: 1.2rem; background: var(--panel); border-radius: var(--radius); padding: .8rem 1rem; }
.howto summary { cursor: pointer; font-weight: 600; }
.howto ol { padding-left: 1.2rem; }

.card { background: var(--panel); border-radius: var(--radius); padding: 1rem; margin: .8rem 0; }
.options { display: grid; gap: .9rem; }
.options label { display: grid; gap: .35rem; font-size: .92rem; color: var(--muted); }
.options label.check { display: flex; align-items: center; gap: .6rem; color: var(--text); }
.options input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }
select, input[type=text], input[type=password], textarea {
  width: 100%; font-size: 1rem; padding: .6rem; border-radius: 10px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); font-family: inherit;
}
textarea { resize: vertical; line-height: 1.6; min-height: 8rem; }
#out-text { min-height: 14rem; }

.pin-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.pin-row.single { grid-template-columns: 1fr; justify-items: center; }
input.pin {
  font-size: 1.6rem; letter-spacing: .5em; text-align: center; padding: .5rem .2rem .5rem .7rem;
  font-variant-numeric: tabular-nums; font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}
input.pin.big { max-width: 14rem; font-size: 2.2rem; }
input.pin.bad { border-color: var(--err); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: .8rem;
  background: var(--panel); border-radius: var(--radius); }
.seg-btn { min-height: 46px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-size: 1rem; font-weight: 600; cursor: pointer; touch-action: manipulation; font-family: inherit; padding: .4rem; }
.seg-btn.on { background: var(--panel-2); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.35); }

.preview-box { margin-top: .8rem; background: #0e0a1a; border-radius: var(--radius); padding: .6rem; }
.preview-box img { display: block; margin: 0 auto; max-width: 100%; max-height: 32dvh; border-radius: 6px; }

.meter-box { margin-top: .8rem; }
.meter { height: 8px; border-radius: 99px; background: var(--panel-2); overflow: hidden; }
.meter div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.meter div.over { background: var(--err); }
.meter-box .note { margin: .4rem 0 0; }

.stack { display: grid; gap: .6rem; margin-top: .8rem; }

.result-img-wrap { display: flex; justify-content: center; background: #0e0a1a; border-radius: var(--radius); padding: .6rem; margin-top: .6rem; }
.result-img-wrap img { max-width: 100%; max-height: 48dvh; display: block; box-shadow: 0 4px 16px rgba(0,0,0,.5); }

.warn-box {
  background: #3a2a0a; border: 1px solid #854d0e; color: #fde68a; border-radius: var(--radius);
  padding: .8rem 1rem; font-size: .9rem;
}

.secret-head { font-size: 1.1rem; margin: .2rem 0 .8rem; }
.file-card { display: flex; align-items: center; gap: .9rem; }
.file-card .icon { font-size: 2.2rem; }
.file-card b { display: block; word-break: break-all; }

.busy {
  position: fixed; inset: 0; z-index: 40; background: rgba(8, 5, 18, .65);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .8rem; font-weight: 600;
  padding: 1rem; text-align: center;
}
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 1.2rem); transform: translateX(-50%);
  background: #1c1530; color: #fff; padding: .7rem 1.1rem; border-radius: 12px; z-index: 50;
  width: max-content; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.45); font-size: .92rem;
}
.toast.err { background: #7f1d1d; }
.note.license { text-align: center; margin-top: 1.5rem; }
.note.license a { color: inherit; }

@media (min-width: 720px) {
  .home-buttons { grid-template-columns: 1fr 1fr; }
}
