:root {
  color-scheme: light;
  --bg: #f7f5ef;
  --ink: #1d2433;
  --muted: #667085;
  --line: #d9dee8;
  --panel: #ffffff;
  --accent: #167c80;
  --accent-dark: #0f5f63;
  --coral: #d85c4a;
  --gold: #c9922f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 24px;
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 32px 0;
  align-items: stretch;
}

.app-shell.quiz-only {
  grid-template-columns: minmax(0, 760px);
  justify-content: center;
}

.app-shell.register-only {
  grid-template-columns: minmax(0, 460px);
  justify-content: center;
}

.screen,
.register-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 50px rgba(29, 36, 51, 0.08);
}

.screen {
  min-height: 620px;
  padding: 36px;
}

.start-screen {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 24px;
}

.start-screen > :not(.key-visual) {
  position: relative;
  z-index: 1;
}

.start-content {
  display: grid;
  gap: 10px;
  padding: 18px 22px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(2px);
}

.result-screen {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 24px;
}

.result-screen > .eyebrow,
.result-screen > h2,
.result-actions {
  align-self: center;
  text-align: center;
}

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

.key-visual {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 0;
  opacity: 0.28;
  filter: saturate(0.95);
  pointer-events: none;
}

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

.result-details {
  display: grid;
  gap: 14px;
  width: 100%;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.result-card {
  display: grid;
  grid-template-columns: 72px minmax(0, 230px) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.result-card-head {
  display: grid;
  justify-items: center;
  gap: 4px;
}

.result-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}

.result-correct .result-mark {
  background: #e4f5f2;
  color: #16805b;
}

.result-wrong .result-mark {
  background: #fff0ee;
  color: var(--coral);
}

.result-images {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.result-images figure {
  margin: 0;
}

.result-images img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef1f5;
}

.result-source {
  object-fit: contain;
}

.result-crop {
  object-fit: cover;
}

.result-images figcaption {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.result-answer-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.result-answer-list div {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px;
}

.result-answer-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.result-answer-list dd {
  margin: 0;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.title-label {
  font-size: 36px;
  line-height: 1.1;
}

h1,
h2 {
  margin: 0;
  line-height: 1.12;
}

h1 {
  max-width: 560px;
  font-size: 44px;
}

h2 {
  font-size: 28px;
}

.primary-button,
.secondary-button,
.secondary-outline-button,
.choice-button,
.tiny-button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-button {
  min-width: 180px;
  padding: 16px 26px;
  background: var(--accent);
  color: #fff;
}

.secondary-outline-button {
  min-width: 160px;
  padding: 16px 22px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.compact-button {
  width: 100%;
  min-width: 0;
  padding: 12px 18px;
}

.form-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.secondary-button {
  width: 100%;
  padding: 12px 18px;
  background: var(--ink);
  color: #fff;
}

.tiny-button {
  padding: 8px 10px;
  background: #eef7f6;
  color: var(--accent-dark);
  font-size: 12px;
}

.primary-button:hover,
.secondary-outline-button:hover,
.secondary-button:hover,
.choice-button:hover,
.tiny-button:hover {
  transform: translateY(-1px);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.hidden {
  display: none !important;
}

.game-head,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.game-tools {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.score-box {
  display: grid;
  place-items: center;
  min-width: 86px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.score-box span,
.notice,
.drop-zone small,
.storage-note {
  color: var(--muted);
  font-size: 13px;
}

.score-box strong {
  font-size: 26px;
}

.quiz-image-wrap {
  position: relative;
  width: 260px;
  height: 260px;
  margin: 28px auto;
}

#quizCanvas {
  display: block;
  width: 260px;
  height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef1f5;
}

.answer-effect {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  font-size: 172px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 5px 24px rgba(29, 36, 51, 0.35);
  animation: effect-pop 780ms ease both;
  pointer-events: none;
}

.effect-correct {
  background: rgba(22, 124, 80, 0.2);
  color: #22a06b;
}

.effect-wrong {
  background: rgba(216, 92, 74, 0.18);
  color: #d85c4a;
}

@keyframes effect-pop {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }

  18% {
    opacity: 1;
    transform: scale(1.08);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

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

.choice-button {
  min-height: 54px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.choice-button.correct {
  border-color: var(--accent);
  background: #e4f5f2;
}

.choice-button.wrong {
  border-color: var(--coral);
  background: #fff0ee;
}

.choice-button:disabled {
  cursor: default;
}

.feedback {
  min-height: 24px;
  margin: 18px 0 0;
  text-align: center;
  color: var(--muted);
  font-weight: 700;
}

.register-panel {
  min-height: 620px;
  padding: 24px;
  align-self: stretch;
}

.app-shell.register-only .register-panel {
  min-height: auto;
}

.panel-head {
  margin-bottom: 18px;
}

.back-button {
  margin: 0 0 14px;
}

.panel-badges {
  display: flex;
  gap: 8px;
  align-items: center;
}

.panel-badges span {
  min-width: 58px;
  padding: 7px 9px;
  border-radius: 999px;
  background: #eef7f6;
  color: var(--accent-dark);
  text-align: center;
  font-weight: 800;
}

.panel-badges .mode-badge {
  min-width: auto;
  background: #fff4db;
  color: #8a5b10;
}

#uploadForm {
  display: grid;
  gap: 12px;
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.drop-zone {
  display: grid;
  place-items: center;
  min-height: 150px;
  border: 2px dashed #aeb8c8;
  border-radius: 8px;
  background: #fbfcfd;
  cursor: pointer;
  text-align: center;
}

.drop-zone.dragover {
  border-color: var(--gold);
  background: #fff8e8;
}

.drop-zone input {
  display: none;
}

.drop-zone span {
  font-weight: 800;
}

#titleInput {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

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

.preview-box img {
  width: 88px;
  height: 70px;
  object-fit: cover;
  border-radius: 6px;
  background: #eef1f5;
}

.preview-label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.preview-box strong {
  display: block;
  overflow-wrap: anywhere;
}

.registered-list {
  display: grid;
  gap: 10px;
  max-height: 270px;
  margin-top: 18px;
  overflow: auto;
}

.registered-item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.registered-item img {
  width: 56px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
}

.registered-item strong {
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .screen,
  .register-panel {
    min-height: auto;
  }

  h1 {
    font-size: 34px;
  }

  .result-card {
    grid-template-columns: 1fr;
  }

  .result-card-head {
    grid-template-columns: auto 1fr;
    justify-items: start;
  }
}

@media (max-width: 720px) {
  body {
    background: #ffffff;
  }

  .app-shell,
  .app-shell.quiz-only,
  .app-shell.register-only {
    display: block;
    width: 100%;
    min-height: 100svh;
    padding: 0;
  }

  .screen,
  .register-panel {
    width: 100%;
    min-height: 100svh;
    padding: 20px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .start-screen {
    min-height: 100svh;
    padding: 24px 16px;
    justify-content: center;
  }

  .start-content {
    width: min(100%, 360px);
    padding: 16px;
  }

  .title-label {
    font-size: clamp(28px, 8.8vw, 38px);
  }

  h1 {
    font-size: clamp(30px, 9vw, 40px);
  }

  .start-actions,
  .result-actions {
    width: min(100%, 360px);
    display: grid;
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-outline-button {
    width: 100%;
    min-width: 0;
  }

  .key-visual {
    opacity: 0.22;
  }

  .game-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: -20px -20px 18px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }

  .game-tools {
    align-items: end;
  }

  .score-box {
    min-width: 72px;
    padding: 8px 10px;
  }

  .score-box strong {
    font-size: 22px;
  }

  .choices {
    gap: 10px;
  }

  .choice-button {
    min-height: 50px;
    padding: 10px 12px;
  }

  .result-screen {
    padding: 22px 14px;
  }

  .result-details {
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }

  .result-images {
    grid-template-columns: 1fr 1fr;
  }

  .register-panel {
    padding: 18px 14px;
  }

  .panel-head {
    position: sticky;
    top: 0;
    z-index: 2;
    margin: -18px -14px 14px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.96);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
  }

  .drop-zone {
    min-height: 128px;
  }

  .registered-list {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: 0;
  }

  .screen,
  .register-panel {
    padding: 20px;
  }

  .choices {
    grid-template-columns: 1fr;
  }

  .game-head,
  .game-tools {
    align-items: stretch;
  }

  .game-tools {
    flex-direction: column;
  }

  .quiz-image-wrap,
  #quizCanvas {
    width: min(260px, 100%);
    aspect-ratio: 1;
  }

  .quiz-image-wrap {
    height: auto;
  }

  #quizCanvas {
    height: 100%;
  }

  .answer-effect {
    font-size: clamp(120px, 58vw, 172px);
  }
}
