:root {
  --bg-1: #e6f0ff;
  --bg-2: #d5e4ff;
  --bg-3: #c4d7ff;
  --ink: #182233;
  --muted: #46566f;
  --card: rgba(255, 255, 255, 0.88);
  --accent: #1d4b8f;
  --accent-strong: #123563;
  --accent-warm: #3a6bb6;
  --shadow: 0 18px 40px rgba(18, 38, 70, 0.16);
  --radius: 24px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.9), transparent 45%),
    radial-gradient(circle at 85% 10%, rgba(165, 198, 255, 0.7), transparent 40%),
    linear-gradient(135deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
  display: flex;
  justify-content: center;
  padding: 28px 16px calc(48px + env(safe-area-inset-bottom));
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  filter: blur(12px);
  opacity: 0.7;
}

body::before {
  background: rgba(58, 107, 182, 0.45);
  top: -120px;
  left: -80px;
}

body::after {
  background: rgba(29, 75, 143, 0.35);
  bottom: -140px;
  right: -80px;
}

.app {
  position: relative;
  z-index: 1;
  width: min(1080px, 96vw);
  display: grid;
  gap: 22px;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  text-shadow: 0 6px 16px rgba(255, 255, 255, 0.6);
}

.title {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 800;
}


.top-area {
  display: grid;
  gap: 18px;
  grid-template-columns: 1fr;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.course {
  display: grid;
  gap: 10px;
  text-align: center;
  border: 2px solid rgba(29, 75, 143, 0.4);
  background: linear-gradient(140deg, rgba(29, 75, 143, 0.18), rgba(58, 107, 182, 0.16));
  box-shadow: 0 22px 40px rgba(18, 54, 96, 0.18);
}

.course-title {
  font-weight: 800;
  font-size: clamp(26px, 4vw, 38px);
  letter-spacing: 0.5px;
  color: var(--accent-strong);
}

.course-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
}

.course-actions {
  display: flex;
  justify-content: center;
}

.stamp-open {
  border: 2px solid rgba(31, 157, 143, 0.35);
  border-radius: 14px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 800;
  background: #fff;
  color: var(--accent-strong);
  cursor: pointer;
  box-shadow: inset 0 -3px 0 rgba(31, 39, 49, 0.08);
}

.stamp-open:active {
  transform: translateY(2px);
}

.stamp {
  display: grid;
  gap: 12px;
}

.stamp-title {
  font-weight: 800;
  font-size: 18px;
}

.stamp-modal-card {
  max-width: 560px;
  width: 100%;
}

.stamp-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stamp-close {
  border: 2px solid rgba(31, 157, 143, 0.25);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 800;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
}

.stamp-status {
  font-weight: 700;
  color: var(--accent-strong);
}

.stamp-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.stamp-fields.is-hidden,
.stamp-actions.is-hidden {
  display: none;
}

.stamp-input {
  border-radius: 12px;
  border: 2px solid rgba(31, 157, 143, 0.3);
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
}

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

.stamp-btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.stamp-btn.secondary {
  background: #fff;
  color: var(--accent-strong);
  border: 2px solid rgba(31, 157, 143, 0.35);
}

.stamp-btn.ghost {
  background: rgba(255, 255, 255, 0.6);
  color: var(--muted);
  border: 2px dashed rgba(84, 98, 111, 0.3);
}

.stamp-btn.is-hidden {
  display: none;
}

.stamp-note {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.stamp-note.is-error {
  color: #d64545;
}

.calendar {
  display: grid;
  gap: 10px;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 16px;
  padding: 12px;
  border: 1px solid rgba(31, 157, 143, 0.18);
}

.calendar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.calendar-title {
  font-weight: 800;
}

.calendar-nav {
  border: 2px solid rgba(31, 157, 143, 0.25);
  background: #fff;
  color: var(--accent-strong);
  font-weight: 800;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
  text-align: center;
}

.calendar-weekdays {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.calendar-cell {
  background: #fff;
  border-radius: 12px;
  padding: 8px 0;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  box-shadow: inset 0 -2px 0 rgba(31, 39, 49, 0.08);
  position: relative;
  overflow: hidden;
}

.calendar-cell.empty {
  background: transparent;
  box-shadow: none;
}

.calendar-cell.stamped {
  background: #fff3ef;
  color: #7f2222;
  overflow: visible;
}

.calendar-cell.today {
  outline: none;
}

.calendar-day {
  position: relative;
  z-index: 1;
}

.stamp-mark {
  position: absolute;
  inset: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 900;
  color: rgba(155, 20, 20, 0.95);
  border: 3px solid rgba(155, 20, 20, 0.85);
  border-radius: 999px;
  transform: rotate(-12deg);
  background: rgba(255, 255, 255, 0.7);
  letter-spacing: 1px;
  text-shadow: 0 1px 0 rgba(209, 61, 61, 0.35);
  white-space: nowrap;
}


.course-select {
  border-radius: 14px;
  border: 2px solid rgba(29, 75, 143, 0.35);
  padding: 14px 16px;
  font-size: 18px;
  font-weight: 700;
  background: #fff;
  color: var(--ink);
}

.course-select:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.app.is-course-locked .top-area,
.app.is-course-locked .keypad-area {
  opacity: 0.5;
  filter: blur(1.5px);
  transition: opacity 0.2s ease, filter 0.2s ease;
}


.problem-card {
  display: grid;
  gap: 12px;
}

.progress {
  font-weight: 700;
  color: var(--muted);
}

.course-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-strong);
}

.question {
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 800;
  letter-spacing: 1px;
  line-height: 1.2;
  min-height: 2.4em;
  display: flex;
  align-items: center;
}

.answer-label {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
}

.answer-display {
  min-height: 52px;
  height: clamp(52px, 12vw, 64px);
  padding: 10px 16px;
  border-radius: 18px;
  background: #fff;
  font-size: clamp(26px, 4vw, 36px);
  font-weight: 800;
  letter-spacing: 2px;
  border: 2px dashed rgba(29, 75, 143, 0.3);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.status {
  min-height: 28px;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-strong);
}

.status.good {
  color: var(--accent-strong);
}

.status.bad {
  color: #d64545;
}

.timer-card {
  display: grid;
  gap: 10px;
  align-content: start;
}

.timer-actions {
  display: grid;
  gap: 10px;
}

.timer-label {
  font-weight: 700;
  color: var(--muted);
}

.timer {
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
}

.restart {
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-warm));
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 10px 20px rgba(29, 75, 143, 0.3);
}

.restart.is-idle {
  background: linear-gradient(135deg, rgba(29, 75, 143, 0.55), rgba(58, 107, 182, 0.55));
  box-shadow: none;
  opacity: 0.78;
}

.restart.is-ready {
  font-size: 18px;
  padding: 14px 18px;
  box-shadow: 0 18px 32px rgba(29, 75, 143, 0.35), 0 0 0 4px rgba(29, 75, 143, 0.12);
  animation: pulseStart 1.6s ease-in-out infinite;
}

.restart:active {
  transform: translateY(2px) scale(0.98);
}

.sound-toggle {
  border: 2px solid rgba(29, 75, 143, 0.4);
  background: #fff;
  color: var(--accent-strong);
  font-size: 15px;
  font-weight: 800;
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: inset 0 -3px 0 rgba(31, 39, 49, 0.08);
}

.sound-toggle.is-off {
  color: var(--muted);
  border-color: rgba(84, 98, 111, 0.4);
  background: rgba(255, 255, 255, 0.7);
}

.sound-toggle:active {
  transform: translateY(2px) scale(0.98);
}

.hint {
  font-size: 13px;
  color: var(--muted);
}

.keypad-area {
  display: grid;
  gap: 16px;
  align-items: center;
}

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

.key,
.ok {
  border: none;
  border-radius: 18px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.key {
  background: #fff;
  font-size: clamp(22px, 3.4vw, 30px);
  padding: 16px 0;
  box-shadow: inset 0 -4px 0 rgba(31, 39, 49, 0.08);
}

.key.backspace {
  font-size: clamp(16px, 2.6vw, 22px);
  letter-spacing: 2px;
}

.key:active {
  transform: translateY(2px);
}

.ok {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
  font-size: clamp(20px, 3.2vw, 28px);
  padding: 16px 0;
  box-shadow: 0 14px 26px rgba(18, 54, 96, 0.35);
}

.ok:active {
  transform: translateY(2px) scale(0.98);
}

.key:disabled,
.ok:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  box-shadow: none;
  transform: none;
}



.ranking {
  display: grid;
  gap: 12px;
}

.ranking-title {
  font-size: 20px;
  font-weight: 800;
}

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

.ranking-tab {
  border: 2px solid rgba(29, 75, 143, 0.25);
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
  border-radius: 14px;
  padding: 10px 12px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ranking-tab.is-active {
  color: var(--accent-strong);
  background: #fff;
  border-color: rgba(29, 75, 143, 0.5);
  box-shadow: 0 10px 18px rgba(29, 75, 143, 0.18);
}

.ranking-tab:active {
  transform: translateY(2px);
}

.ranking-panels {
  display: block;
  margin-top: 10px;
}

.ranking-panel {
  background: rgba(255, 255, 255, 0.7);
  border-radius: 16px;
  padding: 10px 12px 12px;
  border: 1px solid rgba(29, 75, 143, 0.18);
  display: none;
}

.ranking-panel.is-active {
  display: block;
}


.ranking-course {
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin-left: 8px;
}

.ranking-list {
  margin: 0;
  padding-left: 22px;
  display: grid;
  gap: 6px;
  font-weight: 700;
  color: var(--muted);
}

.ranking-list li {
  display: grid;
  gap: 2px;
}

.ranking-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.rank-name {
  color: var(--ink);
  font-weight: 800;
}

.rank-time {
  color: var(--accent-strong);
  font-weight: 800;
}

.rank-date {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(24, 35, 45, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 16px;
}

.modal.hidden {
  display: none;
}

.modal-card {
  background: #fff;
  border-radius: 20px;
  padding: 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.modal-actions {
  display: grid;
  gap: 10px;
}

.modal-title {
  font-size: 20px;
  font-weight: 800;
}

.modal-text {
  color: var(--muted);
  font-weight: 600;
}

.name-input {
  border: 2px solid rgba(29, 75, 143, 0.4);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.save-name {
  border: none;
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 16px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}

.save-last {
  border: 2px solid rgba(29, 75, 143, 0.35);
  border-radius: 14px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
  background: #fff;
  color: var(--accent-strong);
  cursor: pointer;
}

.save-last.is-hidden {
  display: none;
}

.animate-1,
.animate-2,
.animate-3,
.animate-4 {
  animation: floatIn 0.7s ease both;
}

.animate-2 {
  animation-delay: 0.08s;
}

.animate-3 {
  animation-delay: 0.16s;
}

.animate-4 {
  animation-delay: 0.24s;
}

@keyframes floatIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulseStart {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: 0 18px 32px rgba(29, 75, 143, 0.35), 0 0 0 4px rgba(29, 75, 143, 0.12);
  }
  50% {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 22px 36px rgba(29, 75, 143, 0.4), 0 0 0 6px rgba(29, 75, 143, 0.16);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 18px 32px rgba(29, 75, 143, 0.35), 0 0 0 4px rgba(29, 75, 143, 0.12);
  }
}

@media (max-width: 640px) {
  body {
    padding: 18px 12px calc(28px + env(safe-area-inset-bottom));
  }

  .app {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }

  .top-area {
    display: contents;
  }

  .app-header {
    order: 0;
  }

  .course {
    order: 1;
    padding: 14px;
  }

  .problem-card {
    order: 2;
    gap: 8px;
  }

  .timer-card {
    order: 3;
    gap: 8px;
    padding: 12px 14px;
  }

  .keypad-area {
    order: 4;
    padding: 12px;
  }

  .ranking {
    order: 5;
  }

  .course-title {
    font-size: clamp(20px, 5vw, 28px);
  }

  .course-select {
    padding: 10px 12px;
    font-size: 16px;
  }

  .question {
    font-size: clamp(22px, 5vw, 28px);
    min-height: 1.6em;
  }

  .answer-display {
    min-height: 44px;
    height: 44px;
    font-size: clamp(20px, 5vw, 28px);
  }

  .status {
    min-height: 20px;
    font-size: 15px;
  }

  .timer-label,
  .hint {
    display: none;
  }

  .timer {
    font-size: clamp(22px, 5vw, 30px);
  }

  .timer-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .restart {
    font-size: 15px;
    padding: 10px 12px;
    border-radius: 14px;
  }

  .sound-toggle {
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 12px;
  }

  .keys {
    grid-template-columns: repeat(3, minmax(52px, 1fr));
    gap: 8px;
  }

  .key {
    font-size: clamp(20px, 5vw, 26px);
    padding: 12px 0;
  }

  .ok {
    font-size: clamp(18px, 5vw, 24px);
    padding: 12px 0;
  }
}

@media (max-width: 420px) {
  body {
    padding: 14px 10px calc(24px + env(safe-area-inset-bottom));
  }

  .card {
    padding: 14px;
  }

  .keypad-area {
    padding: 10px;
  }

  .keys {
    gap: 6px;
  }

  .key,
  .ok {
    padding: 10px 0;
  }
}
@media (min-width: 860px) {
  .top-area {
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  }
}

