* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: "BIZ UDPGothic", "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
  background: #f4f6f8;
  color: #222;
  touch-action: manipulation;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
}

.screen {
  display: none;
  min-height: 100vh;
  padding: 24px;
}

.screen.active {
  display: block;
}

.panel,
.game-panel {
  width: min(960px, 100%);
  margin: 0 auto;
  background: white;
  border-radius: 24px;
  padding: 32px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

h1,
h2 {
  text-align: center;
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 6vw, 3.5rem);
}

h2 {
  font-size: clamp(1.6rem, 4vw, 2.6rem);
}

.lead {
  text-align: center;
  line-height: 1.7;
}

.question-inputs {
  display: grid;
  gap: 16px;
  margin: 28px 0;
}

.question-inputs label {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 12px;
  align-items: center;
  font-weight: 700;
}

.question-inputs input {
  min-height: 58px;
  padding: 10px 16px;
  border: 3px solid #c7ccd1;
  border-radius: 14px;
  font-size: 1.5rem;
}

.question-inputs input:focus {
  outline: 4px solid rgba(0, 110, 220, 0.18);
  border-color: #006edc;
}

fieldset {
  border: 2px solid #d6dbe0;
  border-radius: 16px;
  padding: 16px;
  margin: 18px 0;
}

legend {
  font-weight: 800;
  padding: 0 8px;
}

.radio-card {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  margin: 4px 8px 4px 0;
  padding: 8px 14px;
  background: #f0f3f5;
  border-radius: 12px;
  font-weight: 700;
}

.radio-card input {
  width: 22px;
  height: 22px;
}

.primary-button,
.secondary-button,
.small-button {
  border: none;
  border-radius: 14px;
  font-weight: 800;
  min-height: 54px;
  padding: 12px 22px;
}

.primary-button {
  background: #006edc;
  color: white;
}

.secondary-button {
  background: #e8edf2;
  color: #222;
}

.small-button {
  background: white;
  border: 2px solid #ccd2d7;
  min-height: 44px;
}

#start-button {
  display: block;
  width: min(440px, 100%);
  margin: 24px auto 0;
  font-size: 1.4rem;
}

.error {
  color: #b00020;
  font-weight: 800;
  text-align: center;
  min-height: 1.5em;
}

.game-header {
  width: min(960px, 100%);
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.progress {
  background: white;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 800;
}

.answer-area,
.tile-area {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: center;
  gap: 14px;
  min-height: 150px;
  padding: 18px;
  border-radius: 18px;
}

.answer-area {
  background: #f9fbfc;
  border: 4px dashed #b8c1c9;
  margin-bottom: 26px;
}

.tile-area {
  background: #edf2f6;
}

.char-tile,
.answer-tile {
  display: grid;
  place-items: center;
  min-width: 84px;
  min-height: 84px;
  padding: 8px;
  border-radius: 16px;
  background: white;
  border: 4px solid #59636c;
  font-weight: 800;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.char-tile {
  box-shadow: 0 5px 0 #abb2b8;
}

.char-tile.selected {
  transform: translateY(4px);
  box-shadow: 0 1px 0 #abb2b8;
}

.size-medium .char-tile,
.size-medium .answer-tile {
  font-size: 2.2rem;
}

.size-large .char-tile,
.size-large .answer-tile {
  font-size: 3rem;
  min-width: 96px;
  min-height: 96px;
}

.size-xlarge .char-tile,
.size-xlarge .answer-tile {
  font-size: 4rem;
  min-width: 118px;
  min-height: 118px;
}

.answer-placeholder {
  min-width: 84px;
  min-height: 84px;
  border: 3px dashed #c6ccd1;
  border-radius: 14px;
}

.message {
  min-height: 2.2em;
  text-align: center;
  font-size: 1.5rem;
  font-weight: 900;
  margin: 20px 0;
}

.message.correct {
  color: #087a2c;
}

.message.incorrect {
  color: #b00020;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 14px;
}

.next-button {
  display: block;
  margin: 18px auto 0;
  width: min(320px, 100%);
}

.hidden {
  display: none !important;
}

.trace-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 18px;
  margin-bottom: 18px;
}

.trace-toolbar label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 800;
  min-width: 220px;
}

.trace-toolbar input {
  width: 100%;
}

.canvas-wrap {
  width: 100%;
  min-height: 360px;
  border: 4px solid #aeb6bd;
  border-radius: 18px;
  overflow: hidden;
  background: white;
  touch-action: none;
}

#trace-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
  touch-action: none;
}

.finish-panel {
  text-align: center;
  margin-top: 7vh;
}

.finish-mark {
  font-size: 7rem;
  line-height: 1;
  margin-bottom: 14px;
}

@media (max-width: 640px) {
  .screen {
    padding: 12px;
  }

  .panel,
  .game-panel {
    padding: 20px;
    border-radius: 18px;
  }

  .question-inputs label {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .char-tile,
  .answer-tile,
  .answer-placeholder {
    min-width: 66px;
    min-height: 66px;
  }

  .size-large .char-tile,
  .size-large .answer-tile {
    min-width: 76px;
    min-height: 76px;
    font-size: 2.4rem;
  }

  .size-xlarge .char-tile,
  .size-xlarge .answer-tile {
    min-width: 92px;
    min-height: 92px;
    font-size: 3.2rem;
  }
}
