:root {
  --primary: #1e88e5;
  --primary-dark: #1565c0;
  --secondary: #e91e63;
  --secondary-dark: #c2185b;
  --purple: #6a1b9a;
  --ok: #2e7d32;
  --bad: #c62828;
  --bg: #eef2f7;
  --card: #fff;
  --text: #263238;
  --muted: #6b7a86;
  --line: #e1e6ec;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(circle at 20% 0%, #dfe9f7 0, transparent 50%), var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.app { max-width: 560px; margin: 0 auto; padding: 14px 14px calc(30px + env(safe-area-inset-bottom)); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; color: var(--primary-dark); min-width: 0; }
.brand span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-icon { color: var(--secondary); font-size: 22px; }
.top-actions { display: flex; gap: 6px; flex-shrink: 0; }
.chip-btn {
  border: none; border-radius: 999px; padding: 8px 12px; background: var(--purple); color: #fff;
  font-weight: 700; font-size: 13px; cursor: pointer; transition: transform .15s, background .15s;
}
.chip-btn:hover { background: #4a148c; transform: translateY(-1px); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(30, 60, 90, .08); padding: 22px; }
.h1 { margin: 0 0 4px; font-size: 22px; color: var(--primary-dark); }
.h2 { margin: 10px 0 6px; font-size: 20px; color: var(--primary-dark); }

.field { display: block; margin: 18px 0; }
.field > span { display: flex; justify-content: space-between; font-weight: 700; font-size: 14px; margin-bottom: 8px; color: #455a64; }
.counter { font-style: normal; font-weight: 600; color: var(--muted); font-size: 12px; }
input[type=text] {
  width: 100%; padding: 14px; border: 2px solid var(--line); border-radius: 10px; font-size: 17px;
  transition: border-color .2s, box-shadow .2s; background: #fbfcfe;
}
input[type=text]:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(30,136,229,.12); }
input.uppercase { text-transform: uppercase; letter-spacing: .5px; }
input.invalid { border-color: var(--bad); }

.choice-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
#setChoices { grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); }
.choice {
  flex: 1 1 auto; min-width: 70px; border: 2px solid var(--line); background: #fbfcfe; border-radius: 10px;
  padding: 12px 14px; font-size: 15px; font-weight: 700; cursor: pointer; color: var(--text); transition: all .15s;
}
.choice small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; margin-top: 2px; }
.choice:hover { border-color: #b3d4f5; }
.choice.active { border-color: var(--primary); background: #e3f2fd; color: var(--primary-dark); }

.btn {
  border: none; border-radius: 10px; padding: 14px 16px; font-size: 16px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: all .15s; color: #fff; background: var(--primary);
}
.btn:hover { filter: brightness(.95); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); }
.btn-secondary { background: var(--secondary); }
.btn-grey { background: #78909c; }
.btn-success { background: #43a047; }
.btn-ghost { background: #eef3f8; color: var(--primary-dark); }
.btn-small { padding: 8px 12px; font-size: 14px; }
.btn-block { width: 100%; margin-top: 14px; }
.template-status { text-align: center; margin-top: 10px; min-height: 18px; }

.resume { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: #fff8e1; border: 1px solid #ffe082; padding: 12px; border-radius: 10px; margin-bottom: 14px; }
.resume-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Quiz */
.quiz-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.quiz-meta { display: flex; gap: 6px; }
.tag { background: #e3f2fd; color: var(--primary-dark); padding: 5px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.tag-alt { background: #fce4ec; color: var(--secondary-dark); }
.progress { height: 8px; background: #e3e8ee; border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width .3s; }
.q-number { font-size: 13px; font-weight: 700; color: var(--muted); margin: 12px 0 8px; }
.q-text { font-size: 20px; font-weight: 600; line-height: 1.45; margin-bottom: 18px; min-height: 58px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%; padding: 14px; border-radius: 12px;
  background: #f8fafc; border: 2px solid var(--line); font-size: 17px; cursor: pointer; color: var(--text); transition: all .12s;
}
.option:hover { background: #eef6fe; }
.option .letter {
  flex-shrink: 0; width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  border: 2px solid #cfd8dc; background: #fff; font-weight: 800;
}
.option.selected { border-color: var(--primary); background: #e3f2fd; color: var(--primary-dark); font-weight: 700; }
.option.selected .letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.quiz-nav { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 20px; }
.quiz-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #455a64; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }
.link-btn { background: none; border: none; color: var(--secondary-dark); font-weight: 700; font-size: 14px; cursor: pointer; padding: 6px 0; }
.kbd-hint { margin-top: 10px; }
kbd { background: #eef1f5; border: 1px solid #d5dbe2; border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 11px; }
@media (hover: none) { .kbd-hint { display: none; } }

/* Palette */
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-bottom: 10px; flex-wrap: wrap; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: #eceff1; border: 1px solid #cfd8dc; margin-left: 6px; }
.dot-done { background: #43a047; border-color: #43a047; }
.dot-cur { background: #fff; border: 2px solid var(--secondary); }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 6px; max-height: 55vh; overflow-y: auto; padding: 2px; }
.palette button { aspect-ratio: 1; border-radius: 8px; border: 1px solid #cfd8dc; background: #eceff1; font-weight: 700; cursor: pointer; font-size: 13px; color: #37474f; }
.palette button.done { background: #43a047; border-color: #43a047; color: #fff; }
.palette button.cur { outline: 3px solid var(--secondary); outline-offset: 1px; }

/* Result */
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid #e3f2fd; border-top-color: var(--primary); margin: 20px auto; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.score-ring { position: relative; width: 170px; height: 170px; margin: 6px auto 4px; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #e8eef4; stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--primary); stroke-width: 12; stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset 1.2s ease-out, stroke .3s; }
.score-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.score-text strong { font-size: 44px; line-height: 1; color: var(--primary-dark); }
.score-text span { color: var(--muted); font-weight: 700; }
.details { background: #f1f8f2; border: 1px solid #c8e6c9; border-radius: 12px; padding: 14px; margin-top: 14px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-grid div { display: flex; flex-direction: column; }
.detail-grid span { font-size: 12px; color: var(--muted); }
.qlist { margin-top: 12px; font-size: 13px; word-break: break-word; }
.qlist > span { font-weight: 700; display: block; margin-bottom: 2px; }
.download-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.alert { background: #ffebee; color: var(--bad); padding: 12px; border-radius: 10px; margin-top: 12px; white-space: pre-line; }

/* Modals */
.modal { position: fixed; inset: 0; background: rgba(15, 25, 35, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 1000; }
.modal-box { background: #fff; width: 100%; max-width: 400px; border-radius: 16px; box-shadow: 0 20px 50px rgba(0,0,0,.25); padding: 18px 20px; animation: pop .18s ease-out; max-height: 90vh; display: flex; flex-direction: column; }
.modal-wide { max-width: 540px; }
.modal-title { font-size: 19px; font-weight: 800; color: var(--primary-dark); margin-bottom: 8px; }
.modal-body { font-size: 16px; line-height: 1.5; color: #455a64; white-space: pre-line; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(8px); } }

.hof-wrap { overflow-y: auto; margin-top: 10px; max-height: 60vh; }
.hof { width: 100%; border-collapse: collapse; font-size: 13px; }
.hof th, .hof td { border-bottom: 1px solid #eee; padding: 8px 6px; text-align: center; }
.hof th { background: var(--purple); color: #fff; position: sticky; top: 0; }
.hof td:nth-child(2) { text-align: left; font-weight: 700; }

/* About (water ripple) */
#about-ripple-box {
  background: #000033 center/cover no-repeat; border: 2px solid #b8860b; border-radius: 20px; padding: 30px;
  text-align: center; box-shadow: 0 0 20px #b8860b; width: 100%; max-width: 500px; position: relative; overflow: hidden;
  color: #fff; max-height: calc(100dvh - 30px); overflow-y: auto;
}
.about-content { position: relative; z-index: 2; text-shadow: 0 1px 4px rgba(0,0,0,.85), 0 0 2px rgba(0,0,0,.6); }
.about-title { font-size: 24px; font-weight: 700; color: #ffa500; }
.about-by { font-size: 20px; margin-top: 20px; }
.about-yt { font-size: 18px; margin: 180px 0 20px; }
.about-finger { font-size: 24px; margin: 10px 0; }
.about-link { color: #ffa500; font-weight: 700; text-decoration: none; }
.about-link:hover { text-decoration: underline; }
@media (max-width: 480px) { .about-yt { margin-top: 60px; } #about-ripple-box { padding: 20px 16px; } }

.footer { text-align: center; margin-top: 18px; }
.wm { position: fixed; bottom: 14px; right: 16px; font-size: 22px; font-weight: 800; opacity: .18; pointer-events: none; user-select: none; z-index: 5; }

@media (max-width: 420px) {
  .card { padding: 18px 16px; }
  .chip-btn span { display: none; }
  .q-text { font-size: 18px; }
  .option { font-size: 16px; padding: 12px; }
}
