:root {
  --bg: #fffdf8;
  --surface: #ffffff;
  --soft: #fff4e0;
  --line: #eedfc8;
  --text: #2a2118;
  --muted: #8a7a66;
  --accent: #e07a0b;
  --accent-ink: #ffffff;
  --accent-soft: #ffe7c2;
  --warn: #b4410a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Noto Sans Thai", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
}

* { margin: 0; }
body { background: var(--bg); min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin-bottom: .25rem; }
h2 { font-size: 1.02rem; font-weight: 600; margin-bottom: .75rem; }
.muted { color: var(--muted); }
.error { color: var(--warn); margin: .5rem 0; }
.notice { background: var(--soft); border-left: 3px solid var(--accent); padding: .6rem .8rem; margin-top: .75rem; border-radius: 4px; }

/* header */
.top { display: flex; align-items: center; gap: 1rem; padding: .7rem 16px; border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: wrap; }
.brand { font-weight: 600; color: var(--text); }
.top nav { display: flex; gap: .9rem; flex-wrap: wrap; }
.top nav a { color: var(--muted); }
.top nav a.on { color: var(--accent); font-weight: 600; }
.logout { margin-left: auto; }

/* layout */
main { padding: 1.25rem 16px 2rem; }
.narrow { max-width: 30rem; margin: 0 auto; }
.form { max-width: 64rem; margin: 0 auto; padding-bottom: 8rem; }
.wide { max-width: 80rem; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: .9rem; margin-top: 1rem; }
.stack label { display: flex; flex-direction: column; gap: .25rem; font-size: .92rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* controls */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; background: var(--surface); min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .person:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: .45rem .9rem; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.link { border: 0; background: none; color: var(--muted); padding: 0; }
button:disabled { cursor: default; opacity: .7; }

/* list of teams */
.list { list-style: none; padding: 0; margin-top: 1.25rem; display: flex; flex-direction: column; gap: .5rem; }
.list > li > a { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.list > li > a:hover { border-color: var(--accent); text-decoration: none; }
.tag { font-size: .8rem; padding: .1rem .55rem; border-radius: 99px; background: var(--soft); color: var(--muted); white-space: nowrap; }
.tag.done { background: var(--accent-soft); color: var(--warn); }

/* questionnaire */
.intro { margin-bottom: 1.25rem; }
.q { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.num { display: inline-flex; align-items: center; justify-content: center; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--accent-soft); color: var(--warn); font-size: .85rem; margin-right: .5rem; }
.hint { font-size: .85rem; color: var(--muted); margin-top: .5rem; }
.hint.full, .label.full { animation: pulse .6s; }
@keyframes pulse { 0%, 100% { color: var(--muted); } 50% { color: var(--warn); } }

.fu-row { display: flex; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.fu-row input { flex: 1 1 9rem; }
.fu-row input:first-child { flex: 3 1 14rem; }
.notes { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; }
.q7-note { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.q7-note[hidden] { display: none; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip { border-radius: 99px; padding: .35rem .8rem; }
.chip .muted, .person .muted { font-size: .8rem; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip[aria-pressed="true"] .muted { color: var(--accent-soft); }

.matrix { display: flex; flex-direction: column; gap: .6rem; }
.q5-row { border: 0; padding: .5rem 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: .4rem 1rem; }
.q5-row legend { float: left; min-width: 10rem; padding: 0; font-weight: 500; }
.seg { display: flex; flex-wrap: wrap; gap: .3rem; flex: 1 1 18rem; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: inline-block; padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 99px; font-size: .88rem; cursor: pointer; }
.seg input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }

.groups { display: flex; flex-direction: column; gap: .8rem; margin-top: .8rem; }
.label { font-size: .88rem; color: var(--muted); margin-bottom: .35rem; cursor: default; }
.drop { list-style: none; padding: .5rem; min-height: 2.8rem; display: flex; flex-wrap: wrap; gap: .45rem; border-radius: var(--radius); align-content: flex-start; }
.drop.target { border: 2px dashed var(--line); background: var(--soft); }
.drop.pool { border: 1px solid var(--line); }
.drop.armed { border-color: var(--accent); }
.drop.over { background: var(--accent-soft); }
.drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.person { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .35rem; padding: .35rem .8rem; border-radius: 99px; background: var(--surface); border: 1px solid var(--line); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.target .person { border-color: var(--accent); }
.person.sel { background: var(--accent); color: var(--accent-ink); }
.person.sel .muted { color: var(--accent-soft); }
.person.dragging { opacity: .35; }
.person .why { display: none; padding: .15rem .4rem; font-size: .85rem; border-radius: 6px; touch-action: auto; }
.drop[data-group="no"] .person { border-radius: var(--radius); }
.drop[data-group="no"] .why { display: inline-block; }
.person.ghost { position: fixed; left: 0; top: 0; pointer-events: none; margin: -1rem 0 0 -2rem; z-index: 10; border-color: var(--accent); }

.bar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding: .6rem 16px; }
.bar-row { max-width: 64rem; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.errors { max-width: 64rem; margin: 0 auto; padding: 0 0 0 1.2rem; color: var(--warn); font-size: .88rem; }
.errors:empty { display: none; }
.errors li { margin-bottom: .15rem; }

/* admin */
.cards { display: flex; gap: .75rem; flex-wrap: wrap; margin: 1rem 0 1.5rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem 1rem; min-width: 8rem; }
.card b { display: block; font-size: 1.4rem; }
.card small { color: var(--muted); }
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; vertical-align: top; }
th { background: var(--soft); font-weight: 600; font-size: .82rem; color: var(--muted); }
td.c, th.c { text-align: center; }
tr:last-child td { border-bottom: 0; }
.g { display: inline-block; min-width: 1.6rem; text-align: center; border-radius: 6px; padding: 0 .35rem; font-weight: 600; }
.g1 { background: var(--accent); color: var(--accent-ink); }
.g2 { background: var(--accent-soft); color: var(--warn); }
.g3 { background: var(--soft); color: var(--text); }
.g4 { background: #f3e6e0; color: var(--warn); }
.flag { display: inline-block; font-size: .75rem; padding: 0 .45rem; border-radius: 99px; border: 1px solid var(--warn); color: var(--warn); margin: 0 .2rem .2rem 0; }
.dot { color: var(--accent); font-weight: 700; }
.filters { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.section { margin-top: 1.75rem; }
.section h2 { margin-bottom: .6rem; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; }
dl.kv dt { color: var(--muted); }
.pw { font-family: ui-monospace, Menlo, monospace; background: var(--soft); padding: .1rem .4rem; border-radius: 4px; user-select: all; }
form.inline { display: inline; }
.between { justify-content: space-between; }
.gap-b { margin-bottom: .75rem; }
.item { padding: .7rem 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

@media (min-width: 640px) {
  .groups { flex-direction: row; }
  .groups > .grp { flex: 1; min-width: 0; }
}
.card small + b + small { display: block; }
button.link.accent { color: var(--accent); }
ul.plain { padding-left: 1.1rem; }
.icon { flex: none; vertical-align: -.15em; }
.with-icon { display: inline-flex; align-items: center; gap: .3rem; }
p.with-icon { display: flex; }
.icon-btn { border: 0; background: none; padding: .15rem; color: var(--muted); line-height: 0; border-radius: 6px; }
.icon-btn.on { background: var(--accent); color: var(--accent-ink); padding: .25rem; }
.icon-btn.on:hover { background: var(--warn); }
.icon-btn:hover { background: var(--soft); }
.flag-list { row-gap: .7rem; margin-top: 1.25rem; }
.flag-list dt { scroll-margin-top: 1rem; }
.flag-list dt:target + dd { color: var(--accent); font-weight: 600; }
a.flag:hover { text-decoration: none; background: var(--soft); }
.link-out { word-break: break-all; }

/* wide screens: Q5 as an aligned table — fixed name column, 4 equal option columns */
@media (min-width: 900px) {
  .q5-row { display: block; padding: .35rem .5rem; border-radius: 6px; }
  .q5-row:hover, .q5-row:focus-within { background: var(--soft); }
  .q5-row legend { width: 15rem; min-width: 0; padding-top: .3rem; }
  .seg { display: grid; grid-template-columns: repeat(4, 1fr); margin-left: 15.5rem; }
  .seg span { display: block; text-align: center; }
}
.logout { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.whoami { color: var(--muted); font-size: .9rem; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.nowrap { flex-wrap: nowrap; gap: .3rem; }
.name-in { padding: .25rem .45rem; width: 11rem; }
.wide-users { max-width: 46rem; }
.ver { color: var(--muted); font-size: .75rem; text-align: center; padding: 1rem 16px 2rem; }
