* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #f4f7ff;
  color: #1a1a1a;
}

body.theme-po {
  background: #eef7ff;
}

body.theme-po .container {
  border-radius: 18px;
}

body.theme-po .button {
  background: #2f83ff;
}

body.theme-po .button.info {
  background: #00a98f;
}

body.theme-po .game-board {
  border-color: #b7d4ff;
  background: linear-gradient(180deg, #dff0ff 0%, #f5fbff 100%);
}

body.theme-vo {
  background: #111723;
  color: #e8eefc;
}

body.theme-vo .container,
body.theme-vo .card,
body.theme-vo .game-stats > div {
  background: #1a2333;
  border-color: #2f3e58;
  color: #e8eefc;
}

body.theme-vo .table th,
body.theme-vo .table td {
  border-bottom-color: #2f3e58;
}

body.theme-vo .button {
  background: #7b5bff;
}

body.theme-vo .button.info {
  background: #0cb2c8;
}

body.theme-vo .button.secondary {
  background: #3d4e6e;
}

body.theme-vo .game-board {
  border-color: #42557a;
  background: linear-gradient(180deg, #1b2940 0%, #131d2e 100%);
}

body.theme-adult {
  background: #f1f4f8;
  color: #1d2430;
}

body.theme-adult .container,
body.theme-adult .card,
body.theme-adult .game-stats > div {
  background: #ffffff;
  border-color: #d8e0ea;
}

body.theme-adult .button {
  background: #2b5f97;
}

body.theme-adult .button.info {
  background: #3d7a70;
}

body.theme-adult .button.secondary {
  background: #556476;
}

body.theme-adult .game-board {
  border-color: #c8d5e6;
  background: linear-gradient(180deg, #edf2f8 0%, #f8fbff 100%);
}

.container {
  max-width: 920px;
  margin: 40px auto;
  padding: 24px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}

.teacher-dashboard {
  max-width: 1200px;
}

h1 {
  margin-top: 0;
}

.narrow {
  max-width: 540px;
}

.row {
  display: flex;
  gap: 16px;
  align-items: center;
}

.between {
  justify-content: space-between;
}

.actions {
  display: flex;
  gap: 12px;
  margin: 12px 0 18px;
}

.button {
  display: inline-block;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: #376dff;
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  font-family: Arial, sans-serif;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}

.button.secondary {
  background: #616b7f;
}

.button.danger {
  background: #c63636;
}

.button.info {
  background: #0c8a8a;
}

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

.action-group .button {
  white-space: nowrap;
}

.license-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
}

.class-link {
  color: #1a1a1a;
  text-decoration: none;
  font-weight: 600;
}

.class-link.active {
  color: #376dff;
}

.form {
  display: grid;
  gap: 12px;
  margin: 10px 0 14px;
}

.form label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}

.form input,
.form-inline input,
.form-inline select {
  width: 100%;
  border: 1px solid #d8deee;
  border-radius: 8px;
  padding: 10px 12px;
}

.form-inline {
  display: flex;
  gap: 10px;
}

.card {
  background: #fff;
  border: 1px solid #ebeff9;
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid #ebeff9;
  text-align: left;
  padding: 10px 8px;
}

.error {
  color: #bb1d1d;
  font-weight: 700;
}

.success {
  color: #0d7a34;
  font-weight: 700;
}

.game-layout {
  max-width: 980px;
  position: relative;
}

.ivy-buddy {
  display: none;
}

.help-anchor {
  position: absolute;
  top: 12px;
  right: 12px;
}

.help-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #376dff;
  color: #fff;
  font-weight: 700;
  cursor: help;
}

.help-tooltip {
  position: absolute;
  top: 36px;
  right: 0;
  width: 260px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #1f2b45;
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 5;
}

.help-anchor:hover .help-tooltip,
.help-anchor:focus-within .help-tooltip {
  opacity: 1;
  transform: translateY(0);
}

.game-stats {
  display: grid;
  grid-template-columns: repeat(8, minmax(100px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.game-stats > div {
  background: #fff;
  border: 1px solid #ebeff9;
  border-radius: 10px;
  padding: 8px 10px;
}

.stat-card strong {
  display: inline-block;
  margin-left: 4px;
}

.game-board {
  position: relative;
  width: 100%;
  height: 340px;
  border-radius: 12px;
  border: 2px solid #dce5ff;
  background: linear-gradient(180deg, #eaf0ff 0%, #f8faff 100%);
  overflow: hidden;
}

.falling-letter {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #376dff;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
}

.hint {
  color: #606980;
  margin: 10px 0;
}

.tip-text {
  margin: 8px 0 2px;
  font-weight: 600;
  color: #2a4f76;
}

.keyboard-visual {
  display: grid;
  grid-template-columns: repeat(10, minmax(24px, 1fr));
  gap: 5px;
  margin-top: 10px;
}

.keyboard-key {
  border: 1px solid #c8d8f2;
  border-radius: 8px;
  background: #f7fbff;
  text-align: center;
  padding: 6px 4px;
  font-size: 12px;
}

.keyboard-key.target {
  background: #dff5ff;
  border-color: #67b9e6;
  font-weight: 700;
}

.keyboard-key.hit {
  background: #e8ffd9;
  border-color: #9dd765;
}

.keyboard-key.miss {
  background: #ffe4e4;
  border-color: #f3a6a6;
}

.fx-pop,
.fx-miss {
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 6;
}

.fx-pop {
  border: 3px solid #8cd64b;
  animation: fxPop 420ms ease-out forwards;
}

.fx-miss {
  border: 3px solid #ff6b6b;
  animation: fxMiss 420ms ease-out forwards;
}

.board-shake {
  animation: boardShake 220ms ease-in-out;
}

@keyframes fxPop {
  0% { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

@keyframes fxMiss {
  0% { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(2); opacity: 0; }
}

@keyframes boardShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

body.theme-po .ivy-buddy {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

body.theme-po .ivy-buddy-inline {
  margin-bottom: 8px;
}

body.theme-po .ivy-avatar {
  width: 82px;
  height: 82px;
  border-radius: 18px;
  background: linear-gradient(180deg, #7ed6f5 0%, #4cb5e8 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 6px 14px rgba(28, 94, 165, 0.25);
  transform-origin: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

body.theme-po .ivy-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: auto;
}

body.theme-po .ivy-avatar.mood-happy {
  transform: scale(1.05) rotate(-2deg);
  box-shadow: 0 8px 18px rgba(30, 140, 90, 0.35);
}

body.theme-po .ivy-avatar.mood-focus {
  transform: scale(1);
  filter: saturate(1.06);
}

body.theme-po .ivy-avatar.mood-oops {
  transform: translateY(1px) rotate(2deg);
  box-shadow: 0 8px 18px rgba(220, 80, 80, 0.35);
}

body.theme-po .ivy-bubble {
  background: #f2f8ff;
  border: 2px solid #b7ea70;
  color: #1f3553;
  border-radius: 16px;
  padding: 8px 12px;
  font-weight: 600;
}

body.theme-po .stat-score { background: #e8f5ff; border-color: #9fdcff; }
body.theme-po .stat-correct { background: #edffe8; border-color: #b7ea70; }
body.theme-po .stat-wrong { background: #fff3f3; border-color: #ffb5b5; }
body.theme-po .stat-missed { background: #fff7eb; border-color: #ffd59a; }
body.theme-po .stat-combo { background: #e9f8ff; border-color: #8cd64b; }
body.theme-po .stat-time { background: #edf1ff; border-color: #b9c7ff; }
body.theme-po .stat-accuracy { background: #ecfff3; border-color: #8cd64b; }
body.theme-po .stat-stars { background: #fffde9; border-color: #ffd468; }

body.theme-po .stat-combo.combo-pulse {
  animation: comboPulse 420ms ease;
}

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

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 35, 56, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  width: min(760px, 96vw);
  max-height: 88vh;
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  padding: 18px;
  border: 1px solid #dce5f5;
}

.guide-letters,
.guide-fingers {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.guide-chip {
  border-radius: 999px;
  padding: 6px 10px;
  background: #eef4ff;
  border: 1px solid #b9ccf9;
  font-weight: 600;
}

.guide-keyboard {
  display: grid;
  grid-template-columns: repeat(10, minmax(26px, 1fr));
  gap: 6px;
  margin: 12px 0;
}

.guide-key {
  border: 1px solid #c8d8f2;
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
  font-size: 13px;
  background: #f8fbff;
}

.guide-key.active {
  background: #dff5ff;
  border-color: #6cc5ea;
  font-weight: 700;
}

body.theme-po .modal-dialog {
  border: 2px solid #8cd64b;
  background: #f9fdff;
}

.muted {
  color: #5a6578;
  font-size: 0.95rem;
}

.achievements-card .achievement-count,
.achievements-compact .achievement-count {
  margin: 0 0 12px;
  font-size: 0.95rem;
}

.achievement-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.achievement-item {
  border: 1px solid #dce5f5;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fafcff;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.achievement-title {
  font-weight: 700;
  color: #1a2744;
}

.achievement-desc {
  font-size: 0.9rem;
  color: #4a5568;
}

.achievement-time {
  font-size: 0.8rem;
  color: #7a8698;
}

.achievement-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.achievement-chip {
  border-radius: 999px;
  padding: 6px 12px;
  background: linear-gradient(135deg, #e8f4ff 0%, #f3e8ff 100%);
  border: 1px solid #b9c7f0;
  font-size: 0.85rem;
  font-weight: 600;
  color: #243252;
}

body.theme-vo .achievement-item {
  background: #222c3d;
  border-color: #3d4e6e;
}

body.theme-vo .achievement-title {
  color: #e8eefc;
}

body.theme-vo .achievement-desc,
body.theme-vo .muted {
  color: #a8b4cc;
}

body.theme-vo .achievement-chip {
  background: linear-gradient(135deg, #2a3350 0%, #352a50 100%);
  border-color: #5a4a8a;
  color: #e8e4ff;
}

.achievement-toast-root {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.achievement-toast {
  pointer-events: auto;
  background: #fff;
  border: 2px solid #7b5bff;
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 8px 28px rgba(30, 40, 80, 0.2);
  animation: achievementSlideIn 0.35s ease;
}

.achievement-toast-out {
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

.achievement-toast-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 0.95rem;
}

.achievement-toast-title strong {
  color: #5b2ee8;
}

.achievement-toast-desc {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: #4a5568;
  line-height: 1.35;
}

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

body.theme-po .achievement-toast {
  border-color: #2f83ff;
}

body.theme-po .achievement-toast-title strong {
  color: #1a5fd4;
}
