:root {
  --bg: #eef1f5;
  --card: #ffffff;
  --soft: #f5f7fa;
  --text: #2c3e50;
  --muted: #7f8c8d;
  --border: #dcdfe3;
  --primary: #5096d6;
  --primary-dark: #3f7fbd;
  --gray-btn: #95a5a6;
  --ok: #27ae60;
  --err: #e74c3c;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { padding: 12px 12px 40px; }
.page { max-width: 640px; margin: 0 auto; background: var(--card); border-radius: 18px; padding: 22px 18px 28px; }
h1 { text-align: center; font-size: 26px; margin: 6px 0 18px; }
h2 { font-size: 20px; margin: 0 0 8px; }
.sub { text-align: center; color: var(--muted); font-style: italic; margin: -8px 0 16px; line-height: 1.4; }
label.f { display: block; font-weight: 700; margin: 16px 0 8px; font-size: 16px; }
input[type=text], input[type=number], input[type=date], input[type=time] {
  width: 100%; padding: 13px 14px; font-size: 17px; border: 2px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--text); outline: none; -webkit-appearance: none; appearance: none; min-height: 50px;
}
input:focus { border-color: var(--primary); }
.hint { color: var(--muted); font-size: 14px; margin-top: 6px; line-height: 1.4; }
.box { background: var(--soft); border-radius: 12px; padding: 16px; margin-top: 18px; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-top: 16px; background: #fff; }
.card.soft { background: var(--soft); }
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 15px; font-size: 18px;
  background: var(--primary); color: #fff; cursor: pointer; margin-top: 22px; font-weight: 500; }
.btn:active { background: var(--primary-dark); }
.btn.small { padding: 12px; font-size: 16px; margin-top: 10px; font-weight: 700; }
.btn.gray { background: var(--gray-btn); width: auto; display: inline-block; padding: 10px 18px; font-size: 16px; margin: 0; border-radius: 8px; }
.btn.ok { background: var(--ok); }
.btn:disabled { opacity: .55; }
.check { display: flex; gap: 12px; align-items: flex-start; border: 1px solid #d6e2ee; background: #f4f7fa;
  border-radius: 12px; padding: 16px; margin-top: 22px; }
.check input { width: 24px; height: 24px; margin-top: 2px; flex: none; }
.check b { font-size: 18px; }
.progress { height: 10px; background: #e6eaee; border-radius: 6px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; background: var(--primary); width: 0; transition: width .2s; }
.center { text-align: center; }
.muted { color: var(--muted); }
code.k { background: #eef1f4; border-radius: 6px; padding: 3px 8px; letter-spacing: 3px; font-family: ui-monospace, Menlo, monospace; white-space: nowrap; }
.q-title { font-size: 17px; margin: 4px 0 12px; }
.letters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.letters button { border: 2px solid var(--primary); background: #fff; color: var(--primary); border-radius: 10px;
  padding: 14px 0; font-size: 17px; font-weight: 700; cursor: pointer; }
.letters button.on { background: var(--primary); color: #fff; }
.score-row { display: flex; align-items: center; gap: 14px; margin-top: 14px; font-weight: 700; }
.score-row input { width: 80px; text-align: center; padding: 8px; min-height: 40px; font-size: 16px; }
math-field { display: block; width: 100%; font-size: 22px; border: 2px solid var(--border); border-radius: 10px;
  padding: 10px; min-height: 56px; background: #fff; }
math-field:focus-within { border-color: var(--primary); }
.err { color: var(--err); margin-top: 10px; font-weight: 600; }
.notice { background: #fdecea; color: #a23b2c; padding: 12px 14px; border-radius: 10px; margin-top: 14px; }
.success { text-align: center; padding: 20px 0; }
.success .big { font-size: 56px; }
.code-big { font-size: 34px; font-weight: 800; letter-spacing: 4px; margin: 10px 0; }
.review-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 10px; }
.review-list div { background: var(--soft); border-radius: 8px; padding: 8px; font-size: 15px; text-align: center; overflow: hidden; }
.review-list .open { grid-column: 1 / -1; text-align: left; }
.row2 { display: flex; gap: 10px; }
.row2 > * { flex: 1; }
.hidden { display: none !important; }

/* Key preview in the create page */
.keyhead { margin-top: 14px; font-weight: 600; line-height: 1.5; }
.keygrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; margin-top: 8px; }
.kchunk { background: #eef1f4; border-radius: 6px; padding: 4px 6px; font-family: ui-monospace, Menlo, monospace;
  font-size: 15px; letter-spacing: 1px; white-space: nowrap; line-height: 1.5; }
.kchunk small { color: var(--muted); font-size: 11px; letter-spacing: 0; margin-right: 4px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }

/* Region picker in the check page */
.regions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.regions button { padding: 12px 8px; border: 2px solid var(--border); border-radius: 10px; background: #fff;
  color: var(--text); font-size: 15px; line-height: 1.25; cursor: pointer; }
.regions button.on { border-color: var(--primary); background: var(--primary); color: #fff; font-weight: 600; }
.regions button:last-child:nth-child(odd) { grid-column: 1 / -1; }

/* Certificate design picker (create page) */
.designs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.designs button { padding: 4px 4px 6px; border: 2px solid var(--border); border-radius: 10px; background: #fff; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text); font-size: 11.5px; }
.designs button img { width: 100%; aspect-ratio: 595 / 842; object-fit: cover; border-radius: 5px; display: block; }
.designs button.on { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(80,150,214,.25); font-weight: 700; }
.design-preview { margin-top: 12px; text-align: center; }
.design-preview img { width: 100%; max-width: 340px; border-radius: 8px; box-shadow: 0 4px 18px rgba(0,0,0,.12); }

/* Key edit mode */
.card.changed { border-color: #e6a23c; box-shadow: 0 0 0 2px rgba(230,162,60,.25); }
.card.notice-ok { background: #fff8ec; border-color: #f0c987; }
.card.notice-ok > div { margin-top: 4px; }
.notice.info { background: #eaf3fc; color: #1d4f86; }

/* Attached question files */
.file-list { margin: 10px 0 4px; display: flex; flex-direction: column; gap: 6px; }
.file-item { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.file-item .fi { font-size: 22px; }
.file-item .fn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.file-item .fs { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.file-item button { border: 0; background: #fdecea; color: #c0392b; border-radius: 8px; width: 34px; height: 34px; font-size: 16px; cursor: pointer; flex: none; }

/* Question pages (check page) */
.pages-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.pages-head h2 { margin: 0; }
.pages-head .btn { width: auto; margin: 0; padding: 8px 12px; }
.pages { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.pages img { width: 100%; height: auto; display: block; border-radius: 8px; background: #fff; border: 1px solid var(--border); cursor: zoom-in; }
.viewer { position: fixed; inset: 0; z-index: 50; background: #1d232a; display: flex; flex-direction: column; }
.viewer .vbar { display: flex; gap: 8px; padding: 10px; background: #12161b; }
.viewer .vbar button { flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: #2c3640; color: #fff; font-size: 18px; font-weight: 700; }
.viewer .vbar #vClose { flex: 2; background: #5096d6; font-size: 16px; }
.vscroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 10px; }
.vscroll img { display: block; margin: 0 auto 10px; background: #fff; border-radius: 6px; }

/* Countdown timer */
body.has-timer { padding-top: 64px; }
.timer { position: fixed; top: 0; left: 0; right: 0; z-index: 40; display: flex; justify-content: center; align-items: center; gap: 8px;
  height: 52px; background: #1b2a55; color: #fff; font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.timer small { font-size: 13px; font-weight: 600; opacity: .8; }
.timer.warn { background: #e58e1a; }
.timer.danger { background: #d63031; animation: tpulse 1s infinite; }
@keyframes tpulse { 50% { opacity: .75; } }

/* region / grade pickers: native select = wheel picker on phones */
select.pick { width: 100%; padding: 14px 40px 14px 14px; font-size: 16px; border: 2px solid var(--border); border-radius: 10px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%236b7785' stroke-width='2'/%3E%3C/svg%3E") no-repeat right 14px center;
  -webkit-appearance: none; appearance: none; color: var(--text, #1f2933); margin-bottom: 6px; }
select.pick:focus { outline: none; border-color: var(--primary); }
select.pick.empty { color: #8a94a0; }
