@import url('https://fonts.googleapis.com/css2?family=Patrick+Hand&family=Nunito:wght@400;500;600;700;800;900&display=swap');

:root {
  --paper: #fbf7e9;
  --paper-deep: #f3ecd8;
  --ink: #34352f;
  --muted: #77776b;
  --blue: #8eb8c8;
  --blue-dark: #47798b;
  --yellow: #f5d66e;
  --coral: #e9957d;
  --green: #9dbb91;
  --line: rgba(83, 111, 126, .18);
  --shadow: 0 18px 50px rgba(82, 70, 43, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  padding: 34px 18px;
  color: var(--ink);
  font-family: "Nunito", "Trebuchet MS", sans-serif;
  background-color: #eee7d5;
  background-image:
    radial-gradient(rgba(95, 79, 48, .075) .7px, transparent .7px),
    linear-gradient(135deg, rgba(255,255,255,.28), transparent 55%);
  background-size: 7px 7px, auto;
}

button, input, textarea { font: inherit; }

.page {
  width: min(100%, 760px);
  margin: 0 auto;
  position: relative;
}

.paper {
  position: relative;
  overflow: hidden;
  padding: 38px clamp(22px, 6vw, 58px) 42px;
  border: 1px solid rgba(121, 105, 69, .18);
  border-radius: 7px 7px 13px 7px;
  background-color: var(--paper);
  background-image:
    linear-gradient(90deg, transparent 0, transparent 42px, rgba(222, 139, 126, .22) 43px, transparent 44px),
    repeating-linear-gradient(to bottom, transparent 0, transparent 35px, var(--line) 36px, transparent 37px);
  box-shadow: var(--shadow);
}

.paper::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: .25;
  background-image: radial-gradient(rgba(102, 86, 56, .18) .55px, transparent .55px);
  background-size: 5px 5px;
}

.paper > * { position: relative; }

.topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 34px;
  margin-bottom: 4px;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px;
  border: 1.5px solid rgba(71, 121, 139, .35);
  border-radius: 999px;
  background: rgba(255,255,255,.55);
}

.language-switch button {
  border: 0;
  border-radius: 999px;
  padding: 6px 13px;
  color: var(--blue-dark);
  background: transparent;
  font-size: .78rem;
  font-weight: 900;
  cursor: pointer;
  transition: background .18s, color .18s, transform .18s;
}

.language-switch button[aria-pressed="true"] {
  color: white;
  background: var(--blue-dark);
  box-shadow: 0 2px 5px rgba(40, 76, 89, .18);
}

.language-switch button:active { transform: scale(.96); }

.hero {
  text-align: center;
  padding: 2px 0 24px;
}

.eyebrow {
  display: inline-block;
  margin: 0 0 3px;
  color: var(--coral);
  font-family: "Patrick Hand", cursive;
  font-size: 1.2rem;
  letter-spacing: .08em;
  transform: rotate(-2deg);
}

h1 {
  margin: 0;
  color: #354b51;
  font-family: "Patrick Hand", "Comic Sans MS", cursive;
  font-size: clamp(3.8rem, 12vw, 6.2rem);
  font-weight: 400;
  line-height: .92;
  letter-spacing: .015em;
  text-shadow: 2px 3px 0 rgba(142, 184, 200, .25);
}

.title-underline {
  width: 190px;
  height: 9px;
  margin: 5px auto 12px;
  border-top: 4px solid var(--yellow);
  border-radius: 50%;
  transform: rotate(-1.5deg);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: .98rem;
  font-weight: 700;
  letter-spacing: .015em;
}

.doodle-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 23px;
  margin: 0 auto 24px;
  color: var(--blue-dark);
}

.doodle {
  width: 38px;
  height: 38px;
  opacity: .88;
}

.doodle:nth-child(1) { transform: rotate(-13deg); color: var(--coral); }
.doodle:nth-child(2) { transform: rotate(8deg); color: var(--blue-dark); }
.doodle:nth-child(3) { transform: rotate(12deg); color: #c49a35; }

.form-area {
  max-width: 560px;
  margin: 0 auto;
}

.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 15px;
  color: #4b666c;
  font-family: "Patrick Hand", cursive;
  font-size: 1.55rem;
  font-weight: 400;
}

.section-heading::after {
  content: "";
  height: 1px;
  flex: 1;
  border-top: 2px dashed rgba(71, 121, 139, .3);
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 17px;
  margin-bottom: 22px;
}

.field { min-width: 0; }

label {
  display: block;
  margin: 0 0 7px 2px;
  color: #55584f;
  font-size: .88rem;
  font-weight: 900;
}

.field-hint {
  margin: 5px 0 0 3px;
  color: #898779;
  font-size: .72rem;
  font-weight: 700;
}

input, textarea {
  width: 100%;
  border: 1.5px solid rgba(100, 123, 119, .34);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: rgba(255,255,255,.72);
  box-shadow: inset 0 2px 4px rgba(79, 69, 44, .035);
  transition: border-color .18s, box-shadow .18s, background .18s;
}

input {
  height: 49px;
  padding: 0 14px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: .04em;
}

input::placeholder, textarea::placeholder {
  color: #aaa797;
  font-weight: 600;
  opacity: 1;
}

input:focus, textarea:focus {
  border-color: var(--blue-dark);
  background: #fffefa;
  box-shadow: 0 0 0 3px rgba(142, 184, 200, .22);
}

input[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: #cf7467;
  box-shadow: 0 0 0 3px rgba(207, 116, 103, .12);
}

.reading-section { margin-top: 3px; }

.reading-label-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.reading-label-row label { margin-bottom: 7px; }

.paste-note {
  color: #898779;
  font-size: .72rem;
  font-weight: 700;
  white-space: nowrap;
}

textarea {
  display: block;
  min-height: 210px;
  padding: 15px 16px;
  resize: vertical;
  font-size: .98rem;
  line-height: 1.75;
}

.text-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 7px 2px 0;
  color: #898779;
  font-size: .72rem;
  font-weight: 700;
}

.start-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 27px 0 0;
}

.action-button {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 0;
  min-height: 72px;
  padding: 10px 16px;
  border: 2px solid;
  border-radius: 12px 10px 13px 9px;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, filter .15s;
}

.powerup-button {
  border-color: #b68c2c;
  color: #51401d;
  background: var(--yellow);
  box-shadow: 0 5px 0 #c6a548, 0 8px 13px rgba(103, 83, 36, .12);
  transform: rotate(-.6deg);
}

.challenge-button {
  border-color: #5c8998;
  color: #294c57;
  background: #b9d6df;
  box-shadow: 0 5px 0 #7faab8, 0 8px 13px rgba(55, 91, 103, .12);
  transform: rotate(.6deg);
}

.action-button:hover {
  filter: brightness(1.035);
  transform: translateY(-2px) rotate(0);
}

.powerup-button:hover {
  box-shadow: 0 7px 0 #c6a548, 0 10px 16px rgba(103, 83, 36, .14);
}

.challenge-button:hover {
  box-shadow: 0 7px 0 #7faab8, 0 10px 16px rgba(55, 91, 103, .14);
}

.action-button:active {
  transform: translateY(3px) rotate(0);
  box-shadow: 0 2px 0 currentColor;
}

.action-button:focus-visible, .language-switch button:focus-visible {
  outline: 3px solid var(--blue-dark);
  outline-offset: 4px;
}

.action-title {
  font-family: "Patrick Hand", cursive;
  font-size: 1.65rem;
  line-height: 1.05;
  letter-spacing: .035em;
}

.action-japanese {
  font-size: .78rem;
  font-weight: 900;
  opacity: .82;
}

.button-star {
  position: absolute;
  top: 8px;
  right: 12px;
  font-family: sans-serif;
  font-size: 1rem;
  opacity: .7;
}

.status {
  min-height: 25px;
  margin: 16px 0 0;
  color: #477b55;
  text-align: center;
  font-size: .84rem;
  font-weight: 800;
}

.status.error { color: #b65349; }

.footer-note {
  margin: 12px 0 0;
  color: #999383;
  text-align: center;
  font-family: "Patrick Hand", cursive;
  font-size: 1rem;
  letter-spacing: .02em;
}

.corner-pencil {
  position: absolute;
  right: 19px;
  bottom: 17px;
  width: 76px;
  height: 76px;
  opacity: .5;
  transform: rotate(16deg);
  pointer-events: none;
}




/* Full-screen dialog */

.fullscreen-dialog {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  color: var(--ink);
  background: #eee7d5;
  overflow: auto;
}

.fullscreen-dialog::backdrop {
  background: rgba(52, 53, 47, .65);
}

/* Notebook sheet */

.powerup-container {
  position: relative;
  width: min(100%, 760px);
  min-height: 100%;
  margin: 0 auto;
  padding: 30px clamp(22px, 6vw, 58px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(121, 105, 69, .18);
  background-color: var(--paper);
  background-image:
    linear-gradient(
      90deg,
      transparent 0,
      transparent 42px,
      rgba(222, 139, 126, .22) 43px,
      transparent 44px
    ),
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 35px,
      var(--line) 36px,
      transparent 37px
    );
  box-shadow: var(--shadow);
}

.powerup-container > * {
  position: relative;
}

/* Header */

.powerup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 17px;
  border-bottom: 2px dashed rgba(71, 121, 139, .3);
}

.student-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-weight: 900;
  font-size: 1.15rem;
}

.header-label,
.section-label {
  color: var(--muted);
  font-size: .75rem;
  font-weight: 900;
  letter-spacing: .08em;
}

.dialog-close {
  border: 1.5px solid rgba(71, 121, 139, .35);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  color: var(--blue-dark);
  background: rgba(255,255,255,.65);
  font-size: 1.2rem;
  cursor: pointer;
}

/* Dialog title */

.dialog-title {
  margin: 22px 0 0;
  color: #354b51;
  text-align: center;
  font-family: "Patrick Hand", cursive;
  font-size: 2.5rem;
  font-weight: 400;
}

/* Progress */

.powerup-progress {
  margin-top: 25px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 9px;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 900;
}

#phrase-counter {
  color: var(--blue-dark);
}

#phrase-progress {
  display: block;
  width: 100%;
  height: 11px;
  appearance: none;
  border: 1px solid rgba(71, 121, 139, .25);
  border-radius: 20px;
  overflow: hidden;
}

#phrase-progress::-webkit-progress-bar {
  background: rgba(142, 184, 200, .2);
}

#phrase-progress::-webkit-progress-value {
  background: var(--blue);
  border-radius: 20px;
}

#phrase-progress::-moz-progress-bar {
  background: var(--blue);
  border-radius: 20px;
}

/* Current phrase */

.phrase-area {
  margin-top: 45px;
  text-align: center;
}

.phrase-area .section-label {
  color: var(--coral);
  font-family: "Patrick Hand", cursive;
  font-size: 1.2rem;
}

.phrase-card {
  margin-top: 15px;
  padding: 30px 22px;
  border: 1.5px solid rgba(100, 123, 119, .3);
  border-radius: 9px;
  color: var(--ink);
  background: rgba(255,255,255,.78);
  box-shadow: 0 4px 0 rgba(82, 70, 43, .09);
  font-size: clamp(1.5rem, 5vw, 2.35rem);
  font-weight: 800;
  line-height: 1.5;
  overflow-wrap: break-word;
}

.instruction {
  margin-top: 20px;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 700;
}

/* Microphone button */

.microphone-area {
  margin-top: 32px;
  text-align: center;
}

.microphone-button {
  width: 135px;
  height: 135px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 0 auto;
  border: 2px solid #b68c2c;
  border-radius: 50%;
  color: #51401d;
  background: var(--yellow);
  box-shadow: 0 5px 0 #c6a548,
              0 8px 13px rgba(103, 83, 36, .12);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
}

.mic-icon {
  font-size: 2.4rem;
}

#microphone-button-text {
  font-family: "Patrick Hand", cursive;
  font-size: 1.35rem;
  font-weight: 400;
}

.microphone-button:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c6a548;
}

/* Recording state */
.microphone-button.recording {
  border-color: #b75e4d;
  color: #63372e;
  background: var(--coral);
  box-shadow: 0 5px 0 #c57460,
              0 0 20px rgba(233, 149, 125, .4);
  animation: pulse 1s infinite;
}

/* Processing state */
.microphone-button.processing {
  border-color: #5c8998;
  color: #294c57;
  background: #b9d6df;
  box-shadow: 0 5px 0 #7faab8;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.microphone-status {
  margin-top: 17px;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
}

/* Recognized speech */

.recognition-area {
  margin-top: 30px;
}

.recognized-text {
  min-height: 58px;
  margin-top: 10px;
  padding: 13px 15px;
  border: 1.5px dashed rgba(71, 121, 139, .35);
  border-radius: 9px;
  color: var(--muted);
  background: rgba(255,255,255,.5);
  font-size: .95rem;
  line-height: 1.6;
}

/* Footer */

.powerup-footer {
  margin-top: auto;
  padding-top: 28px;
  color: #999383;
  text-align: center;
  font-family: "Patrick Hand", cursive;
  font-size: .95rem;
}

/* Mobile */

@media (max-width: 560px) {
  .powerup-container {
    padding: 22px 20px 28px 32px;
    background-image:
      linear-gradient(
        90deg,
        transparent 0,
        transparent 20px,
        rgba(222, 139, 126, .22) 21px,
        transparent 22px
      ),
      repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent 34px,
        var(--line) 35px,
        transparent 36px
      );
  }

  .phrase-area {
    margin-top: 35px;
  }

  .phrase-card {
    padding: 25px 16px;
  }

  .microphone-button {
    width: 120px;
    height: 120px;
  }
}





@media (max-width: 560px) {
  body { padding: 12px 9px; }
  .paper {
    padding: 23px 20px 30px 32px;
    background-image:
      linear-gradient(90deg, transparent 0, transparent 20px, rgba(222, 139, 126, .22) 21px, transparent 22px),
      repeating-linear-gradient(to bottom, transparent 0, transparent 34px, var(--line) 35px, transparent 36px);
  }
  .field-grid { grid-template-columns: 1fr; gap: 13px; }
  .hero { padding-bottom: 17px; }
  .doodle-row { margin-bottom: 19px; }
  textarea { min-height: 190px; }
  .corner-pencil { width: 54px; height: 54px; right: 11px; bottom: 10px; }
  .footer-note { padding-right: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}

/* Results page */

.results-container {
  justify-content: flex-start;
}

.results-content {
  width: 100%;
  max-width: 540px;
  margin: 15px auto 0;
  text-align: center;
}

.results-celebration {
  margin-top: 5px;
  font-size: 3.5rem;
  line-height: 1.2;
}

.results-heading {
  margin: 8px 0 0;
  color: #477b55;
  font-family: "Patrick Hand", cursive;
  font-size: clamp(2.5rem, 9vw, 3.5rem);
  font-weight: 400;
  line-height: 1;
}

.results-subtitle {
  margin: 8px 0 22px;
  color: var(--muted);
  font-size: .95rem;
  font-weight: 800;
}

/* Student details */

.results-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 0 auto 22px;
}

.result-detail {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  min-width: 0;
  padding: 12px 8px;
  border: 1.5px solid rgba(100, 123, 119, .25);
  border-radius: 9px;
  background: rgba(255,255,255,.65);
}

.result-label {
  color: var(--muted);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .06em;
}

.result-value {
  color: #354b51;
  font-size: clamp(1.35rem, 5vw, 1.9rem);
  font-weight: 900;
  line-height: 1.15;
  overflow-wrap: anywhere;
}

.result-time {
  grid-column: 1 / -1;
  padding: 15px 10px;
  background: rgba(245, 214, 110, .25);
  border-color: rgba(182, 140, 44, .35);
}

.result-time .result-value {
  color: #8a6720;
  font-size: clamp(2.5rem, 10vw, 3.5rem);
  letter-spacing: .04em;
}

/* Target text */

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

.target-heading {
  margin: 0 0 8px;
  color: #4b666c;
  font-family: "Patrick Hand", cursive;
  font-size: 1.3rem;
  font-weight: 400;
}

.target-text {
  max-height: 115px;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1.5px dashed rgba(71, 121, 139, .35);
  border-radius: 8px;
  background: rgba(255,255,255,.55);
  color: #68685f;
  font-size: .78rem;
  font-weight: 600;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Closing message and button */

.results-message {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin: 18px 0;
  color: var(--muted);
  font-family: "Patrick Hand", cursive;
  font-size: 1.15rem;
}

.results-close-button {
  width: 100%;
  max-width: 260px;
  min-height: 58px;
  margin: 0 auto;
}

/* Compact mobile layout */

@media (max-width: 560px) {
  .results-content {
    margin-top: 8px;
  }

  .results-celebration {
    font-size: 2.8rem;
  }

  .results-subtitle {
    margin-bottom: 15px;
  }

  .results-info {
    gap: 8px;
    margin-bottom: 15px;
  }

  .result-detail {
    padding: 9px 6px;
  }

  .result-time {
    padding: 10px;
  }

  .target-text {
    max-height: 95px;
  }

  .results-message {
    margin: 12px 0;
  }
}