:root {
  --bg-color: #1a1510;
  --text-color: #e8dcc5;
  --primary-color: #d4af37;
  --primary-hover: #b5952f;
  --accent-color: #8b0000;
  --success-color: #4caf50;
  --glass-bg: rgba(25, 20, 15, 0.85);
  --glass-border: rgba(212, 175, 55, 0.4);
  --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.6);
  --font-sans: "Outfit", "Noto Sans JP", sans-serif;
  --font-serif: "Cinzel", "Noto Serif JP", serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--text-color);
  background: var(--bg-color);
}

.app-container {
  width: 100%;
  height: 100vh;
  position: relative;
  background: url("./images/all_bg.jpg") no-repeat center center/cover;
  background-size: cover;
  overflow: hidden;
}

/* Glassmorphism utility */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 24px;
}

/* Screens */
.screen {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  transition:
    opacity 0.5s ease,
    transform 0.5s ease;
}

.screen.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.95);
  z-index: -1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
  z-index: 10;
}

/* Title Screen */
#title-screen .glass-panel {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  border: none;
  box-shadow: none;
  padding: 40px 20px;
  text-align: center;
  max-width: 650px;
  width: 100%;
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  0% {
    transform: translateY(0px);
  }
  50% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(0px);
  }
}

.game-title {
  font-family: var(--font-serif);
  font-size: 3.5rem;
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 10px;
  letter-spacing: 2px;
}

.game-title .highlight {
  color: var(--primary-color);
  background: linear-gradient(135deg, #f9d423, #ff4e50);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game-subtitle {
  font-size: 1.1rem;
  color: #b0a08a;
  margin-bottom: 40px;
  font-family: var(--font-serif);
}
.game-explain {
  color: var(--text-color);
  margin-bottom: 30px;
}
.btn {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.2rem;
  padding: 16px 40px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 2px;
}

.primary-btn {
  background: linear-gradient(135deg, #3a2e24, #1a1510);
  color: var(--primary-color);
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.6);
  border: 1px solid var(--primary-color);
}

.primary-btn:hover {
  transform: translateY(-2px);
  background: linear-gradient(135deg, #4a3b2e, #2a221b);
  box-shadow: 0 8px 20px rgba(212, 175, 55, 0.3);
}

.primary-btn:active {
  transform: translateY(1px);
}

/* Game Screen */
#game-screen {
  justify-content: flex-start;
  padding: 20px;
}

.game-header {
  width: 100%;
  padding: 15px 20px;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-radius: 16px;
}

.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.mode-badge {
  background: rgba(139, 0, 0, 0.6);
  border: 1px solid var(--primary-color);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  letter-spacing: 2px;
  color: var(--primary-color);
  font-weight: 800;
  font-family: var(--font-serif);
}

.blinking-text {
  animation: slowBlink 2s infinite ease-in-out;
}

@keyframes slowBlink {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

.score-display {
  color: var(--primary-color);
  transition: color 0.3s;
}

.score-flash {
  animation: flashRed 0.5s ease-out;
}

@keyframes flashRed {
  0%,
  100% {
    color: var(--primary-color);
  }
  50% {
    color: #ff0000;
    text-shadow: 0 0 10px rgba(255, 0, 0, 0.8);
  }
}

.timer-bar-wrapper {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.timer-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 700;
  color: #b0a08a;
  margin-bottom: 4px;
  padding: 0 4px;
  font-family: var(--font-serif);
}

.timer-sec-label {
  font-variant-numeric: tabular-nums;
}

.timer-bar-container {
  width: 100%;
  height: 12px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  overflow: hidden;
  box-shadow: inset 0 2px 5px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(212, 175, 55, 0.3);
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #f9d423, #d4af37);
  transform-origin: left;
  transition:
    width 0.1s linear,
    background 0.3s ease;
}

.timer-bar.answer-mode {
  background: linear-gradient(90deg, #d4af37, #b5952f);
}

/* Danger state for timer */
.timer-bar.danger {
  background: linear-gradient(90deg, #d4af37, #8b0000);
}

.game-area-wrapper {
  position: relative;
  flex-grow: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: stretch;
  min-height: 0;
}

.game-area {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.image-container {
  position: relative;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.game-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none; /* Prevent dragging */
}

/* Aha mode specifics */
.game-area.mode-aha .diff-img-overlay {
  opacity: 0;
  /* Transition will be controlled by JS depending on time */
}

/* Feedback Overlay */
.feedback-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

.feedback-overlay.hidden {
  display: none;
}

.feedback-icon {
  width: 200px;
  height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
  animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.feedback-icon.correct {
  color: var(--success-color);
}
.feedback-icon.incorrect {
  color: var(--accent-color);
}

@keyframes popIn {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  80% {
    transform: scale(1.2);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.game-footer {
  margin-top: 15px;
  text-align: center;
}

.instruction {
  font-size: 1rem;
  color: var(--primary-color);
  font-weight: 600;
  background: rgba(20, 15, 10, 0.85);
  display: inline-block;
  padding: 8px 16px;
  border-radius: 4px;
  border: 1px solid rgba(212, 175, 55, 0.5);
  font-family: var(--font-serif);
}

/* Result Screen */
#result-screen {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.result-panel {
  padding: 40px;
  width: 100%;
  max-width: 600px;
  text-align: center;
  margin: auto 0;
}

.result-title {
  font-size: 2.5rem;
  margin-bottom: 20px;
  color: var(--primary-color);
  font-family: var(--font-serif);
  letter-spacing: 2px;
}

.final-score-box {
  background: rgba(0, 0, 0, 0.4);
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 30px;
  border: 1px solid rgba(212, 175, 55, 0.3);
}

.score-label {
  display: block;
  font-size: 1rem;
  color: #b0a08a;
  margin-bottom: 5px;
  font-weight: 700;
  font-family: var(--font-serif);
}

.total-score {
  font-size: 4rem;
  font-weight: 900;
  color: var(--primary-color);
  line-height: 1;
  font-family: var(--font-serif);
}

.result-list {
  list-style: none;
  margin-bottom: 30px;
  text-align: left;
}

.result-item {
  display: flex;
  justify-content: space-between;
  padding: 12px 15px;
  border-bottom: 2px dashed rgba(200, 150, 100, 0.3);
  font-size: 1.1rem;
  color: var(--text-color);
  font-weight: 600;
}

.result-item:last-child {
  border-bottom: none;
}

.result-item .q-mode {
  color: #f57c00;
  font-size: 0.9rem;
  margin-left: 10px;
  font-weight: 800;
}

/* ==========================================================================
   ⑥ Footer
   ========================================================================== */
footer {
  width: 100%;
  font-size: 0.6rem;
  background-color: #fff3e0;
  color: #5c4a3d;
  padding: 2rem 1rem;
  text-align: center;
  margin: 0 auto;
  position: relative;
  border-top: 4px solid #ffe0b2;
}
@media screen and (min-width: 992px) {
  footer {
    font-size: 1rem;
  }
}
footer p {
  line-height: 1.8;
}
footer a {
  color: #ff8c00;
  text-decoration: none;
  font-weight: bold;
}
footer a:hover {
  text-decoration: underline;
}
footer a.link {
  display: block;
  margin: 1em auto;
}
footer .app-explain h2 {
  font-size: 1.2rem;
  font-weight: 900;
  color: #5c4a3d;
}
@media screen and (min-width: 992px) {
  footer .app-explain h2 {
    font-size: 1.8rem;
  }
}
footer .app-explain p {
  font-size: 0.8rem;
  margin: 0.5em auto;
}
@media screen and (min-width: 992px) {
  footer .app-explain p {
    font-size: 1.2rem;
  }
}
footer .site-notice {
  font-size: 0.8rem;
  padding: 0 2rem;
  margin: 0 auto 2rem;
}
@media screen and (min-width: 992px) {
  footer .site-notice {
    font-size: 1rem;
  }
}
footer .app-info {
  margin: 0 auto;
  text-align: center;
}
footer .app-info .app-icon {
  width: 30vw;
  max-width: 100px;
  margin: 2rem auto;
  text-align: center;
  border-radius: 2rem;
  overflow: hidden;
}
footer .app-info .app-badge {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 1rem auto 3rem;
  flex-wrap: wrap;
  gap: 10px;
}
@media screen and (min-width: 992px) {
  footer .app-info .app-badge {
    padding: 0;
    margin: 1rem auto 2rem;
    gap: 20px;
  }
}

@media (max-width: 768px) {
  .generic-text,
  .character-text,
  .game-intro__text,
  #campaign-step p {
    padding: 1.2rem;
  }
}
footer div.site-info {
  width: 100%;
  margin: 0 auto;
}
footer div.site-info .logo {
  width: 20vw;
  display: block;
  margin: 0 auto 1rem;
}
@media screen and (min-width: 992px) {
  footer div.site-info .logo {
    width: 70px;
  }
}
footer div.site-info .logo img {
  display: block;
  margin: 0 auto;
  width: 100%;
}
footer div.site-info .copy {
  font-size: 0.6rem;
  margin: 0 auto;
}
@media screen and (min-width: 992px) {
  footer div.site-info .copy {
    font-size: 1.2rem;
  }
}
footer div.site-info .link {
  font-size: 1rem;
}

/* ==========================================================================
   DEBUG MODE
   ========================================================================== */
.debug-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.85);
  color: white;
  padding: 15px;
  border-radius: 8px;
  z-index: 1000;
  width: 320px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  font-family: monospace;
}
.debug-panel.hidden {
  display: none;
}
.debug-header {
  font-weight: bold;
  font-size: 1.2rem;
  margin-bottom: 15px;
  border-bottom: 1px solid #555;
  padding-bottom: 5px;
  color: #ffb74d;
}
.debug-image-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 15px;
}
.debug-image-buttons button {
  padding: 5px 8px;
  font-size: 11px;
  background: #333;
  color: white;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  flex: 1 1 calc(33% - 5px);
}
.debug-image-buttons button:hover {
  background: #555;
}
.debug-image-buttons button.active {
  background: #ffb74d;
  color: #000;
  border-color: #ffb74d;
}
.debug-info p {
  margin-bottom: 5px;
  font-size: 14px;
}

/* Resizable Box */
.debug-box {
  position: absolute;
  background: rgba(255, 0, 0, 0.2);
  border: 2px dashed red;
  width: 60px;
  height: 60px;
  top: 50%;
  left: 50%;
  transform: translate(
    -50%,
    -50%
  ); /* Move to center initially, but JS will use top/left without transform for easy calculation */
  cursor: move;
  z-index: 100;
  box-sizing: border-box;
  /* To simplify coordinate calculation, we remove transform and use raw top/left */
}
.debug-box .resize-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid red;
  right: -7px;
  bottom: -7px;
  cursor: se-resize;
  border-radius: 50%;
}

/* ==========================================================================
   Small Screen / Mobile Adjustments
   ========================================================================== */
@media (max-width: 480px), (max-height: 700px) {
  .result-panel {
    padding: 20px;
    max-height: 100%;
    overflow-y: auto;
  }
  .result-title {
    font-size: 2rem;
    margin-bottom: 10px;
  }
  .final-score-box {
    padding: 10px;
    margin-bottom: 15px;
  }
  .total-score {
    font-size: 3rem;
  }
  .result-message {
    font-size: 1.2rem !important;
    margin: 10px 0 !important;
  }
  .result-list {
    margin-bottom: 15px;
  }
  .result-item {
    padding: 8px 10px;
    font-size: 1rem;
  }
  .btn {
    padding: 12px 20px;
    font-size: 1rem;
  }

  /* Title Screen Adjustments */
  #title-screen .glass-panel {
    padding: 30px 20px;
    max-height: 100%;
    overflow-y: auto;
  }
  .game-title {
    font-size: 2.5rem;
  }

  /* Game Header Adjustments */
  .status-bar {
    flex-wrap: wrap;
    row-gap: 10px;
    font-size: 0.95rem;
  }
  .question-info {
    order: 1;
    width: 48%;
    text-align: left;
  }
  .score-display {
    order: 2;
    width: 48%;
    text-align: right;
  }
  .mode-badge {
    order: 3;
    margin: 0 auto;
    font-size: 0.85rem;
    padding: 4px 16px;
  }
}
