:root {
  --ink: #1f2937;
  --muted: #64748b;
  --line: #d8dee8;
  --soft-line: #e8edf3;
  --panel: #ffffff;
  --page: #f5f7fa;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #059669;
  --danger: #dc2626;
  --warning: #b45309;
  --shadow: 0 14px 35px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: system-ui, -apple-system, "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .22);
  outline-offset: 2px;
}

.site-header, footer {
  width: min(100% - 32px, 1040px);
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-header { height: 68px; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 800;
  text-decoration: none;
}

.brand-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(37, 99, 235, .22);
}

.brand-icon.large {
  width: 46px;
  height: 46px;
  font-size: 22px;
}

.connection {
  min-width: 86px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.connection i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.connection.online i { background: var(--success); }
.connection.offline i { background: var(--danger); }

.app-shell {
  width: min(100% - 24px, 720px);
  margin: 12px auto 42px;
}

.admin-shell {
  width: min(100% - 24px, 1120px);
  margin: 12px auto 42px;
}

.login-card {
  width: min(100% - 24px, 460px);
  margin: 7vh auto 42px;
}

.card {
  padding: 28px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.loading-card, .empty, .success { text-align: center; }

.link-error {
  max-width: 640px;
  margin: 4vh auto 0;
  border-color: #fecaca;
  background: #fffafa;
  box-shadow: 0 14px 35px rgba(153, 27, 27, .10);
}

.link-error::before {
  content: "!";
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--danger);
  font-size: 32px;
  font-weight: 800;
}

.link-error h1 {
  color: #991b1b;
}

.link-error p {
  max-width: 520px;
  margin: 12px auto 0;
  color: #475569;
  font-size: 16px;
}

.message-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 22px;
}

.message-actions .link-button {
  min-width: 140px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 12px;
  border: 3px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.top-row, .admin-head, .results-head, .timer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
}

.question, .card h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.45;
  letter-spacing: 0;
}

.lead, .empty p, .login-card p, .muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.subtle {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border-radius: 999px;
  color: #047857;
  background: #ecfdf5;
  font-size: 12px;
  font-weight: 700;
}

.pill.closed { color: #475569; background: #f1f5f9; }
.pill.preparing { color: #b45309; background: #fffbeb; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.timer {
  margin: 20px 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.timer-row {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 12px;
}

.timer-row strong {
  color: var(--ink);
  font-size: 18px;
}

.timer-track, .result-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2e8f0;
}

.timer-track span, .result-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width .25s ease;
}

.choices {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.choice {
  position: relative;
  min-height: 64px;
  padding: 12px;
  display: grid;
  grid-template-columns: 36px 1fr 22px;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.choice:has(input:checked) {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.choice input { position: absolute; opacity: 0; }

.choice-letter {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #475569;
  background: #f1f5f9;
  font-size: 13px;
  font-weight: 800;
}

.choice:has(input:checked) .choice-letter {
  color: #fff;
  background: var(--primary);
}

.choice strong { font-size: 15px; overflow-wrap: anywhere; }

.radio {
  width: 20px;
  height: 20px;
  border: 1.5px solid #94a3b8;
  border-radius: 50%;
}

.choice:has(input:checked) .radio { border: 6px solid var(--primary); }

.primary, .secondary, .danger, .mini-tabs button, .poll-list button, .link-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
}

.primary {
  width: 100%;
  margin-top: 18px;
  border: 0;
  color: #fff;
  background: var(--primary);
}

.primary:hover { background: var(--primary-dark); }
.primary:disabled { color: #94a3b8; background: #e2e8f0; cursor: not-allowed; }
.primary.compact { width: auto; margin: 0; }

.secondary, .link-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: #fff;
}

.danger {
  border: 1px solid #fecaca;
  color: var(--danger);
  background: #fff;
}

.full { width: 100%; }

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.success-icon {
  width: 58px;
  height: 58px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--success);
  font-size: 30px;
}

.my-vote {
  margin: 20px 0;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.my-vote span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.my-vote strong { display: block; margin-top: 4px; }

.results {
  margin-top: 20px;
  text-align: left;
}

.results-head h2 {
  margin: 0;
  font-size: 17px;
}

.results-head strong { font-size: 24px; }

.result { margin-top: 14px; }
.result.is-winner .result-track span { background: var(--success); }

.result > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-size: 13px;
}

.result strong { white-space: nowrap; }

.form-grid {
  display: grid;
  gap: 13px;
}

.field {
  display: grid;
  gap: 6px;
  text-align: left;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field input, .field select {
  width: 100%;
  height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

.field input::placeholder { color: #94a3b8; }

.field.has-error input {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, .10);
}

.form-error {
  margin: 0 0 2px;
  padding: 12px 13px;
  border: 1px solid #fecaca;
  border-radius: 8px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 14px;
  line-height: 1.6;
}

.form-error:focus {
  outline: 2px solid rgba(220, 38, 38, .35);
  outline-offset: 2px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.options-editor {
  display: grid;
  gap: 8px;
}

.option-row {
  display: grid;
  grid-template-columns: 1fr 38px;
  gap: 8px;
}

.remove-option {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--danger);
  background: #fff;
}

.home-actions { margin-top: 14px; display: flex; }
.home-actions .link-button { display: inline-flex; align-items: center; }

.mini-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 16px 0;
}

.mini-tabs button {
  border: 1px solid var(--line);
  color: var(--muted);
  background: #fff;
}

.mini-tabs button.is-active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.admin-head {
  align-items: flex-start;
  margin-bottom: 18px;
}

.admin-head h1 {
  margin: 6px 0 4px;
  font-size: 24px;
}

.admin-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.admin-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
}

.poll-list {
  display: grid;
  align-content: start;
  gap: 8px;
}

.poll-list button {
  min-height: 58px;
  display: grid;
  gap: 4px;
  text-align: left;
  border: 1px solid var(--line);
  background: #fff;
}

.poll-list button.is-active {
  border-color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}

.poll-list strong, .poll-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.poll-list span {
  color: var(--muted);
  font-size: 12px;
}

.url-box {
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font-size: 12px;
}

.url-box code {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 18px 0;
}

.metric {
  min-height: 86px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 5px;
  font-size: 24px;
  overflow-wrap: anywhere;
}

.metric .metric-name { font-size: 18px; }
.metric small { color: var(--muted); font-size: 12px; }

.admin-results {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--soft-line);
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--soft-line);
}

.admin-tabs button {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 700;
}

.admin-extra { margin-top: 12px; }

.list-table {
  display: grid;
  gap: 8px;
}

.list-table > div {
  padding: 12px;
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.list-table strong { font-size: 14px; }
.list-table span, .list-table small { color: var(--muted); }

.loading-line {
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
}

.error {
  margin: 10px 0;
  padding: 10px;
  border-radius: 8px;
  color: #991b1b;
  background: #fef2f2;
  font-size: 13px;
}

footer {
  padding: 5px 0 25px;
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  max-width: min(92vw, 520px);
  padding: 11px 15px;
  border-radius: 8px;
  color: #fff;
  background: #0f172a;
  font-size: 13px;
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: .2s;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 820px) {
  .admin-layout { grid-template-columns: 1fr; }
  .poll-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .site-header { height: 62px; }
  .connection { min-width: auto; font-size: 0; }
  .card { padding: 20px; }
  .question, .card h1 { font-size: 23px; }
  .link-error { margin-top: 2vh; }
  .link-error p { font-size: 15px; }
  .message-actions { display: grid; grid-template-columns: 1fr; }
  .message-actions .link-button { width: 100%; }
  .top-row, .admin-head { align-items: flex-start; flex-direction: column; }
  .admin-actions { justify-content: flex-start; }
  .metrics, .settings-grid, .poll-list { grid-template-columns: 1fr; }
  .url-box { grid-template-columns: 1fr; }
  .url-box .secondary { width: 100%; }
  .mini-tabs { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
