:root {
  --bg: #f6f4ed;
  --page-bg-image: url("assets/japan-bg.png");
  --frame-bg-image: url("assets/images/background.jpg");
  --phone-frame-width: 470px;
  --panel: #ffffff;
  --text: #1f2a2e;
  --border: #d8d2c3;
  --accent: #1d5d4f;
  --ok: #4caf50;
  --error: #e53935;
  --tab: #ece8dc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  font-family: "Noto Sans JP", "Segoe UI", sans-serif;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 249, 235, 0.35), rgba(255, 249, 235, 0.35)),
    var(--page-bg-image);
  background-position: center top;
  background-repeat: no-repeat;
  background-size: cover;
  color: var(--text);
}

.app {
  width: min(100%, var(--phone-frame-width));
  margin: 0;
  padding: 20px 14px 24px;
  background-image:
    linear-gradient(rgba(248, 243, 231, 0.86), rgba(248, 243, 231, 0.86)),
    var(--frame-bg-image);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.app.reloading {
  animation: refreshPulse 0.32s ease;
}

.top-bar {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 12px;
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  max-height: 120px;
  overflow: hidden;
  transition:
    max-height 0.28s ease,
    padding 0.28s ease,
    margin-bottom 0.28s ease,
    opacity 0.28s ease,
    transform 0.28s ease,
    border-width 0.28s ease;
}

.top-bar.top-bar-collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  margin-bottom: 0;
  opacity: 0;
  transform: translateY(-10px);
  border-width: 0;
}

.top-bar-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  position: absolute;
  left: 10px;
  top: 10px;
  border: 2px solid #80d64a;
  border-radius: 50%;
  background: linear-gradient(180deg, #56ba2d, #188529);
  color: #ebffe4;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 0 #0b4a19;
  z-index: 3;
}

.top {
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  position: relative;
}

.top h1 {
  margin: 0 0 8px;
  color: var(--accent);
}

.menu-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-toggle {
  width: 42px;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--tab);
  color: var(--text);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.back-home-btn {
  width: auto;
  min-height: 39px;
  padding: 7px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-weight: 700;
}

.app-game {
  padding-top: 14px;
}

.game-btn-index {
  border: 2px solid #80d64a !important;
  background: linear-gradient(180deg, #56ba2d, #188529) !important;
  color: #ebffe4 !important;
  font-weight: 800;
  border-radius: 999px !important;
  box-shadow: 0 4px 0 #0b4a19 !important;
}

.game-btn-index:hover {
  filter: brightness(1.03);
}

.game-title-banner {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 10px;
  padding: 8px 18px;
  border-radius: 10px;
  background: linear-gradient(180deg, #d14838, #b52f20);
  color: #fff5e8 !important;
  font-weight: 900;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 12px rgba(120, 39, 25, 0.28);
}

.game-title-banner::before {
  content: "";
  width: 26px;
  height: 18px;
  border-radius: 3px;
  background:
    radial-gradient(circle at 50% 50%, #d83427 0 6px, transparent 7px),
    #fefdf8;
  border: 1px solid rgba(40, 40, 40, 0.25);
}

.top-menu {
  position: absolute;
  left: 16px;
  top: calc(100% + 8px);
  width: min(430px, calc(100% - 32px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.12);
  z-index: 12;
}

.menu-section + .menu-section {
  margin-top: 10px;
}

.menu-title {
  margin: 0;
  font-size: 0.9rem;
  color: #5a5a5a;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 10px 0 12px;
  flex-wrap: wrap;
}

.tab {
  border: 1px solid var(--border);
  background: var(--tab);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 700;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.lang-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.92rem;
}

.lang-select select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
  font-weight: 700;
  margin-top: 4px;
}

.auth-status {
  color: #555;
  font-size: 0.92rem;
  text-align: center;
}

.save-btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 7px 13px;
  font-weight: 700;
  cursor: pointer;
}

.save-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.save-btn.ghost {
  background: #fff;
  color: var(--accent);
}

.hidden {
  display: none !important;
}

#targetWord {
  font-size: 1.8rem;
  margin: 8px 0 4px;
}

.hint {
  margin: 0;
  color: #616161;
}

#score {
  margin-top: 10px;
  font-weight: 700;
}

.game-progress-track {
  position: relative;
  border: 2px solid #bba88b;
  border-radius: 999px;
  height: 32px;
  overflow: hidden;
  background: linear-gradient(180deg, #f5e9cd, #ebdfbf);
  max-width: 460px;
  margin: 0 auto;
}

.game-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3ba428, #1f8048);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.game-progress-track span {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.98rem;
  font-weight: 900;
  color: #1f1f1f;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
  white-space: nowrap;
}

#livesStatus {
  margin-top: 6px;
  font-weight: 700;
}

.grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  padding: 12px;
  cursor: pointer;
  transition: transform 0.15s ease;
  min-height: 130px;
  animation: cardIn 0.28s ease both;
}

.card:hover {
  transform: translateY(-2px);
}

.card.correct {
  background: var(--ok);
  color: white;
}

.card.wrong {
  background: var(--error);
  color: white;
}

.kanji {
  font-size: 2.1rem;
  font-weight: 700;
  display: block;
}

.reading {
  display: block;
  margin-top: 6px;
  font-size: 0.95rem;
}

.furigana {
  font-size: 1.08rem;
}

.hits {
  margin-top: 8px;
  font-size: 0.85rem;
  opacity: 0.8;
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  padding: 16px;
}

.modal-card {
  width: min(420px, 100%);
  background-image:
    linear-gradient(rgba(255, 252, 245, 0.94), rgba(255, 252, 245, 0.94)),
    var(--frame-bg-image);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}

.modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.auth-form {
  display: grid;
  gap: 10px;
}

.auth-form label {
  display: grid;
  gap: 6px;
  text-align: left;
  font-weight: 700;
  font-size: 0.92rem;
}

.auth-form input,
.auth-form select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.95rem;
  background: #fff;
}

.auth-error {
  min-height: 1rem;
  margin: 0;
  color: #b42318;
  font-size: 0.9rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.google-wrap {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.google-label {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: #666;
  text-align: center;
}

#googleSignInBtn {
  display: flex;
  justify-content: center;
}

.google-status {
  margin: 8px 0 0;
  text-align: center;
  color: #666;
  font-size: 0.86rem;
}

.welcome2 {
  min-height: 60vh;
  width: min(100%, var(--phone-frame-width));
  margin: 0;
  padding: 18px 12px 30px;
  display: grid;
  gap: 12px;
  background-image:
    linear-gradient(rgba(248, 243, 231, 0.32), rgba(248, 243, 231, 0.32)),
    var(--frame-bg-image);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
}

.welcome2-banner {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  height: 70px;
  gap: 12px;
  padding: 8px 18px;
  border-radius: 10px;
  background: linear-gradient(180deg, #d14838, #b52f20);
  color: #fff5e8;
  font-weight: 900;
  font-size: 36px;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 12px rgba(120, 39, 25, 0.28);
}

.welcome2-head {
  justify-self: center;
  width: fit-content;
  display: grid;
  justify-items: center;
  gap: 10px;
}

.welcome2-flag {
  width: 26px;
  height: 18px;
  border-radius: 3px;
  background:
    radial-gradient(circle at 50% 50%, #d83427 0 6px, transparent 7px),
    #fefdf8;
  border: 1px solid rgba(40, 40, 40, 0.25);
}

.welcome2-online {
  margin: 0;
  font-size: 0.84rem;
  color: rgba(63, 58, 50, 0.78);
  font-weight: 600;
  text-align: center;
}

.welcome2-test-alert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 0;
  overflow: hidden;
  margin: 0;
  width: 50.4%;
  min-height: 20px;
  max-height: 25px;
  padding: 2px 6px;
  border: 2px solid #7a0c00;
  border-radius: 8px;
  background: transparent;
  color: #fff8e8;
  font-size: clamp(0.5rem, 1.08vw, 0.6rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.95),
    inset 0 2px 0 rgba(255, 240, 225, 0.35),
    0 4px 0 #7a0c00,
    0 8px 14px rgba(83, 20, 4, 0.4);
}

.welcome2-test-alert::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, #ff5b41 0%, #ef2306 52%, #d11400 100%);
  animation: testAlertBgBlink 0.8s steps(2, start) infinite;
}

.welcome2-test-alert-label {
  position: relative;
  z-index: 1;
}

.welcome2-hero {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  border: 6px solid #f6f0e2;
  padding: 36px 20px 32px;
  text-align: center;
  background-color: rgba(255, 255, 255, 0.4) !important;
  background-image: none !important;
  box-shadow: 0 10px 24px rgba(88, 74, 48, 0.18);
}

.welcome2-skyline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.45;
  background:
    radial-gradient(250px 110px at 20% 70%, #dd9d6f 15%, transparent 70%),
    radial-gradient(270px 110px at 80% 78%, #5d8b6b 10%, transparent 70%),
    radial-gradient(180px 130px at 50% 32%, rgba(74, 127, 175, 0.7) 10%, transparent 72%);
}

.welcome2-hero h1 {
  position: relative;
  margin: 0 0 10px;
  color: #214e45;
  font-size: clamp(1.35rem, 3vw, 2.2rem);
}

.welcome2-hero p {
  position: relative;
  margin: 12px 0 16px;
  color: #343434;
  font-size: clamp(0.98rem, 2.2vw, 1.15rem);
  text-shadow: none;
}

.welcome2-play {
  position: relative;
  display: inline-block;
  text-decoration: none;
  color: #ecffe8;
  font-size: clamp(1.2rem, 3vw, 1.75rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  border-radius: 999px;
  padding: 14px 30px;
  border: 3px solid #7fd646;
  background: linear-gradient(180deg, #58bf2d 0%, #20912a 52%, #0d6322 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 8px 0 #0a4a1a,
    0 12px 18px rgba(19, 70, 22, 0.32);
  transform: translateY(0);
  transition: transform 0.12s ease;
}

.welcome2-play:hover {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 6px 0 #0a4a1a,
    0 10px 14px rgba(19, 70, 22, 0.28);
}

.welcome2-modes {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

.welcome2-mode-card {
  text-decoration: none;
  color: inherit;
  border: 4px solid #f3eee2;
  border-radius: 18px;
  padding: 16px;
  text-align: center;
  background-color: rgba(255, 255, 255, 0.4) !important;
  background-image: none !important;
  box-shadow: 0 6px 14px rgba(88, 74, 48, 0.14);
}

.welcome2-mode-card h2 {
  margin: 0;
  color: #214e45;
  font-size: clamp(1.35rem, 3vw, 2.2rem);
}

.welcome2-mode-card p {
  margin: 12px 0 16px;
  font-size: clamp(0.98rem, 2.2vw, 1.15rem);
  color: #343434;
}

.welcome2-mini-cta {
  display: inline-block;
  border-radius: 999px;
  padding: 8px 24px;
  color: #ebffe4;
  border: 2px solid #80d64a;
  background: linear-gradient(180deg, #56ba2d, #188529);
  font-weight: 800;
  box-shadow: 0 4px 0 #0b4a19;
}

.welcome2-auth-links {
  margin: 6px 0 0;
  text-align: center;
  color: #4a4643;
  font-size: clamp(1rem, 2vw, 1.1rem);
}

.welcome2-auth-links a {
  color: #164f88;
  font-weight: 700;
}

@media (max-width: 760px) {
  .auth-status {
    font-size: 0.85rem;
  }

  #connectBtn {
    padding: 7px 11px;
  }

  .game-progress-track {
    height: 28px;
  }

  .game-progress-track span {
    font-size: 0.8rem;
  }

  .welcome2 {
    padding: 18px 12px 30px;
    gap: 12px;
  }

  .welcome2-modes {
    grid-template-columns: 1fr;
  }

}

@keyframes refreshPulse {
  0% {
    opacity: 0.72;
    transform: translateY(4px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardIn {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes testAlertBgBlink {
  0%,
  49% {
    opacity: 1;
  }
  50%,
  100% {
    opacity: 0.25;
  }
}
