:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #5f6672;
  --border: #d9dde3;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok: #1e8a3e;
  --ok-soft: #e3f4e8;
  --bad: #c62b2b;
  --bad-soft: #fbe6e6;
  --frame: #000000;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171b;
    --surface: #1f2228;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #343943;
    --accent: #6f93f5;
    --accent-text: #0e1220;
    --ok: #4cc26e;
    --ok-soft: #173322;
    --bad: #f06a6a;
    --bad-soft: #3a1b1b;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] {
  display: none !important;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.group-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.95rem;
}

.group-pick select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  cursor: pointer;
}

.group-pick select:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.modes {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.mode {
  border: 0;
  border-radius: 0;
  padding: 8px 12px;
  font-size: 0.95rem;
}

.mode + .mode {
  border-left: 1px solid var(--border);
}

.mode[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.panel {
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel h2 {
  margin-top: 0;
}

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

.status {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.frame {
  position: relative;
  margin: 0 0 16px;
  height: min(55vh, 420px);
  background: var(--frame);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.laugh {
  position: absolute;
  left: 4%;
  bottom: 0;
  width: min(40%, 170px);
  transform: translateY(115%);
  pointer-events: none;
}

.laugh.show {
  animation: laugh-pop 1.6s ease-out both;
}

.dog {
  display: block;
  width: 100%;
  margin-bottom: -12%;
}

.laugh.show .dog {
  animation: laugh-shake 0.16s 0.3s 7 alternate ease-in-out;
}

.laugh-text {
  position: absolute;
  left: 80%;
  bottom: 62%;
  padding: 2px 10px;
  white-space: nowrap;
  font-weight: 800;
  font-size: 1.1rem;
  color: #3a2a1e;
  background: #fff6c7;
  border: 2px solid #3a2a1e;
  border-radius: 999px;
  opacity: 0;
}

.laugh.show .laugh-text {
  animation: laugh-text 1.6s ease-out both;
}

@keyframes laugh-pop {
  0% { transform: translateY(115%); }
  18% { transform: translateY(-4%); }
  26% { transform: translateY(0); }
  80% { transform: translateY(0); }
  100% { transform: translateY(115%); }
}

@keyframes laugh-shake {
  from { transform: translateY(0) rotate(-2deg); }
  to { transform: translateY(-5px) rotate(2deg); }
}

@keyframes laugh-text {
  0%, 18% { opacity: 0; transform: translateY(6px); }
  26%, 78% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(0); }
}

@keyframes laugh-fade {
  0%, 100% { opacity: 0; transform: translateY(0); }
  15%, 80% { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .laugh.show {
    animation-name: laugh-fade;
  }

  .laugh.show .dog {
    animation: none;
  }
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  text-align: left;
  font-size: 1.05rem;
  transition: background 0.15s, border-color 0.15s;
}

.option .key {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.85rem;
}

.option.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
  font-weight: 600;
}

.option.bad {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
  animation: shake 0.35s;
}

.option.ok .key,
.option.bad .key {
  border-color: currentColor;
  color: inherit;
}

.option:disabled {
  cursor: default;
}

.option:disabled:not(.ok):not(.bad) {
  opacity: 0.55;
}

@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .option.bad {
    animation: none;
  }
}

.written {
  display: grid;
  gap: 10px;
}

.written input {
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.written input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.written input.ok {
  background: var(--ok-soft);
  border-color: var(--ok);
  color: var(--ok);
  font-weight: 600;
}

.written input.bad {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
  animation: shake 0.35s;
}

.written-actions {
  display: flex;
  gap: 10px;
}

.written-actions button {
  flex: 1;
}

@media (prefers-reduced-motion: reduce) {
  .written input.bad {
    animation: none;
  }
}

.feedback {
  min-height: 1.5em;
  margin: 12px 0 0;
  text-align: center;
  font-weight: 600;
}

.feedback.ok {
  color: var(--ok);
}

.feedback.bad {
  color: var(--bad);
}

.detail {
  min-height: 1.5em;
  margin: 4px 0 0;
  text-align: center;
  color: var(--muted);
}

.credit {
  max-width: 640px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}
