/* AI Maze Navigator — Neubrutalism Style */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;700;900&display=swap');

:root {
  --bg: #F5F0E8;
  --black: #222;
  --border: 3px solid #222;
  --shadow: 4px 4px 0 #222;
  --primary: #845EF7;
  --primary-light: #B197FC;
  --human-color: #2B8A3E;
  --human-bg: #D8F5E3;
  --ai-color: #845EF7;
  --ai-bg: #F3F0FF;
  --warn: #FF6B6B;
  --gold: #FCC419;
  --white: #fff;
  --radius: 6px;
}

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

html, body {
  height: 100%;
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--black);
  overflow: hidden;
}

/* --- Screens --- */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  flex-direction: column;
  align-items: center;
}
.screen.active {
  display: flex;
}

/* --- Title Screen --- */
.title-screen {
  justify-content: center;
  gap: 24px;
  padding: 24px;
  text-align: center;
}

.title-screen h1 {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.2;
  text-shadow: 3px 3px 0 var(--primary-light);
}

.title-screen .subtitle {
  font-size: clamp(0.9rem, 3vw, 1.2rem);
  color: #555;
  margin-top: -8px;
}

.title-buttons {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  margin-top: 16px;
}

.btn {
  display: inline-block;
  padding: 12px 32px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--white);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 var(--black);
}
.btn:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--black);
}
.btn-primary {
  background: var(--primary);
  color: var(--white);
}
.btn-small {
  padding: 8px 20px;
  font-size: 0.9rem;
}

.title-mascot {
  font-size: clamp(3rem, 12vw, 5rem);
  line-height: 1;
}

/* --- Game Screen --- */
.game-screen {
  padding: 0;
  overflow: hidden;
}

.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  border-bottom: var(--border);
  background: var(--white);
  flex-shrink: 0;
  min-height: 44px;
}

.game-header .stat {
  font-size: 0.9rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.game-header .stat span {
  color: var(--primary);
}

.btn-give-up {
  padding: 4px 14px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.75rem;
  font-weight: 700;
  border: 2px solid var(--warn);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--warn);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-give-up:hover {
  background: var(--warn);
  color: var(--white);
}

.game-body {
  display: flex;
  flex: 1;
  width: 100%;
  overflow: hidden;
  min-height: 0;
}

.maze-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  min-width: 0;
}

#maze-canvas {
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: #333;
  max-width: 500px;
  max-height: 500px;
}

.thoughts-panel {
  width: 320px;
  display: flex;
  flex-direction: column;
  border-left: var(--border);
  background: var(--white);
  flex-shrink: 0;
  min-width: 0;
}

.thoughts-header {
  padding: 8px 12px;
  font-weight: 700;
  font-size: 0.85rem;
  border-bottom: 2px solid #eee;
  color: var(--primary);
}

#thoughts-log {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.chat-msg {
  padding: 6px 10px;
  border-radius: 12px;
  font-size: 0.85rem;
  line-height: 1.4;
  max-width: 95%;
  word-break: break-word;
  animation: chatIn 0.2s ease-out;
}

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

.chat-ai {
  background: var(--ai-bg);
  color: var(--black);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-human {
  background: var(--human-bg);
  color: var(--human-color);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  font-weight: 700;
}

.game-input {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-top: var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

#instruction-input {
  flex: 1;
  padding: 10px 14px;
  font-family: 'Noto Sans JP', sans-serif;
  font-size: 0.95rem;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--white);
  outline: none;
}
#instruction-input:focus {
  box-shadow: 0 0 0 2px var(--primary-light);
}

#btn-send {
  padding: 10px 18px;
}

/* --- Result Screen --- */
.result-screen {
  justify-content: center;
  gap: 20px;
  padding: 24px;
  text-align: center;
}

.result-card {
  background: var(--white);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 40px;
  min-width: 280px;
}

.result-card h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
}

.result-stars {
  font-size: 2.5rem;
  margin: 12px 0;
}

.star {
  display: inline-block;
  color: #ccc;
  transition: color 0.3s;
}
.star.earned {
  color: var(--gold);
  animation: starPop 0.4s ease-out both;
}

@keyframes starPop {
  0% { transform: scale(0.3) rotate(-20deg); opacity: 0; }
  60% { transform: scale(1.2) rotate(5deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.result-stats {
  display: flex;
  gap: 32px;
  justify-content: center;
  margin: 16px 0;
}

.result-stat {
  text-align: center;
}
.result-stat .label {
  font-size: 0.8rem;
  color: #777;
  margin-bottom: 4px;
}
.result-stat .value {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

/* --- Mobile --- */
@media (max-width: 700px) {
  .game-body {
    flex-direction: column;
  }

  .maze-panel {
    flex: none;
    padding: 4px;
  }

  #maze-canvas {
    max-width: calc(100vw - 16px);
    max-height: 55vh;
  }

  .thoughts-panel {
    width: 100%;
    border-left: none;
    border-top: var(--border);
    flex: 1;
    min-height: 120px;
  }

  .game-input {
    padding: 6px 8px;
  }

  .result-stats {
    gap: 20px;
  }
}

/* Scrollbar */
#thoughts-log::-webkit-scrollbar {
  width: 4px;
}
#thoughts-log::-webkit-scrollbar-track {
  background: transparent;
}
#thoughts-log::-webkit-scrollbar-thumb {
  background: var(--primary-light);
  border-radius: 2px;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
