:root {
  --green-park: #2d8a4e;
  --road-gray: #7a7a7a;
  --sidewalk-light: #c8b89a;
  --building-red: #c0392b;
  --building-blue: #2980b9;
  --building-green: #27ae60;
  --building-yellow: #f39c12;
  --water-blue: #3498db;
  --gold: #ffd700;
  --sand: #f4e4c1;
  --dark-brown: #5c3a21;
  --white: #ffffff;
  --shadow: rgba(0, 0, 0, 0.3);
}

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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: linear-gradient(180deg, #4a9e5c 0%, #2d6b3f 100%);
  min-height: 100vh;
  color: var(--white);
  overflow-x: hidden;
}

.home-link {
  position: fixed;
  top: 15px;
  right: 20px;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.4);
  color: var(--sand);
  padding: 8px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 215, 0, 0.2);
}

.home-link:hover {
  background: rgba(255, 215, 0, 0.2);
  color: var(--gold);
  border-color: var(--gold);
}

.game-header {
  text-align: center;
  padding: 20px 0;
}

.game-header h1 {
  font-size: 2.4rem;
  color: var(--gold);
  text-shadow: 3px 3px 6px var(--shadow), 0 0 20px rgba(255, 215, 0, 0.3);
  margin-bottom: 8px;
}

.game-header .subtitle {
  font-size: 1.05rem;
  color: var(--sand);
  opacity: 0.9;
}

.screen {
  display: none;
  animation: fadeIn 0.5s ease;
}

.screen.active {
  display: block;
}

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

.setup-panel {
  background: rgba(92, 58, 33, 0.85);
  border-radius: 20px;
  padding: 40px;
  max-width: 550px;
  margin: 40px auto;
  box-shadow: 0 10px 40px var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 215, 0, 0.3);
}

.setup-panel h2 {
  text-align: center;
  color: var(--gold);
  font-size: 1.8rem;
  margin-bottom: 30px;
}

.form-group {
  margin-bottom: 25px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--sand);
  font-size: 1.05rem;
  font-weight: 600;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 14px 18px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 12px;
  font-size: 1.1rem;
  background: rgba(0, 0, 0, 0.3);
  color: var(--white);
  transition: all 0.3s ease;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}

.setup-info {
  color: var(--sand);
  text-align: center;
  margin-bottom: 20px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.btn {
  display: inline-block;
  padding: 16px 40px;
  border: none;
  border-radius: 14px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold), #ffaa00);
  color: var(--dark-brown);
  box-shadow: 0 6px 20px rgba(255, 215, 0, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(255, 215, 0, 0.6);
}

.btn-small {
  padding: 10px 20px;
  font-size: 1rem;
}

.btn-center {
  display: flex;
  justify-content: center;
  margin-top: 10px;
}

.info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 16px;
  padding: 15px 25px;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}

.info-item {
  text-align: center;
}

.info-item .label {
  font-size: 0.75rem;
  color: var(--sand);
  opacity: 0.8;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.info-item .value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--gold);
}

.progress-bar-container {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 4px;
  margin-bottom: 15px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #ffaa00);
  border-radius: 4px;
  transition: width 0.5s ease;
}

.prompt-panel {
  background: rgba(92, 58, 33, 0.85);
  border-radius: 16px;
  padding: 20px 25px;
  margin-bottom: 15px;
  box-shadow: 0 8px 30px var(--shadow);
  border: 2px solid rgba(255, 215, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 15px;
}

.prompt-icon {
  font-size: 1.3rem;
  color: var(--gold);
  font-weight: 700;
  flex-shrink: 0;
}

.prompt-text {
  font-size: 1.1rem;
  color: var(--white);
  font-weight: 600;
  line-height: 1.4;
}

.direction-hint {
  font-size: 0.85rem;
  color: var(--gold);
  margin-top: 5px;
  font-style: italic;
}

.write-input-area {
  background: rgba(92, 58, 33, 0.75);
  border-radius: 16px;
  padding: 15px 25px;
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
  border: 2px solid rgba(255, 215, 0, 0.2);
}

.write-input-area label {
  color: var(--sand);
  font-weight: 600;
  font-size: 1rem;
}

.write-input-area select {
  padding: 10px 15px;
  border-radius: 10px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  background: rgba(0, 0, 0, 0.3);
  color: var(--white);
  font-size: 1rem;
}

.game-layout-row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  margin-bottom: 15px;
}

.left-panel {
  display: flex;
  flex-direction: column;
  gap: 15px;
  flex-shrink: 0;
  align-items: center;
}

.compass-panel {
  background: rgba(92, 58, 33, 0.75);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 30px var(--shadow);
  border: 2px solid rgba(255, 215, 0, 0.2);
  width: 100%;
}

.compass-panel h3 {
  color: var(--gold);
  text-align: center;
  font-size: 1rem;
  margin-bottom: 12px;
}

.compass-grid {
  display: grid;
  grid-template-columns: repeat(3, 70px);
  grid-template-rows: repeat(3, 55px);
  gap: 4px;
}

.compass-cell {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.compass-cell.n { background: rgba(39, 174, 96, 0.3); }
.compass-cell.s { background: rgba(192, 57, 43, 0.3); }
.compass-cell.e { background: rgba(52, 152, 219, 0.3); }
.compass-cell.w { background: rgba(149, 165, 166, 0.3); }

.arrow {
  font-size: 1.3rem;
  line-height: 1;
}

.dir-label {
  font-size: 0.6rem;
  color: var(--sand);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.compass-cell.center {
  background: rgba(255, 215, 0, 0.1);
}

.compass-cell.center .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gold);
}

.touch-controls-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(92, 58, 33, 0.75);
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 8px 30px var(--shadow);
  border: 2px solid rgba(255, 215, 0, 0.2);
  width: 100%;
}

.touch-controls-panel h3 {
  color: var(--gold);
  font-size: 0.9rem;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-align: center;
}

.touch-grid {
  position: relative;
  width: 200px;
  height: 200px;
}

.touch-btn {
  position: absolute;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(45, 138, 78, 0.7), rgba(45, 107, 63, 0.8));
  border: 3px solid rgba(255, 215, 0, 0.4);
  color: var(--white);
  font-size: 1.3rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
}

.touch-btn small {
  font-size: 0.55rem;
  font-weight: 400;
  opacity: 0.8;
  display: block;
}

.touch-btn.north {
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
}

.touch-btn.south {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
}

.touch-btn.west {
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
}

.touch-btn.east {
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
}

.touch-btn:active {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.4), rgba(255, 170, 0, 0.5));
  border-color: var(--gold);
  transform: translateX(-50%) scale(0.93);
}

.touch-btn.south:active {
  transform: translateX(-50%) scale(0.93);
}

.touch-btn.west:active {
  transform: translateY(-50%) scale(0.93);
}

.touch-btn.east:active {
  transform: translateY(-50%) scale(0.93);
}

.touch-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 215, 0, 0.3), rgba(92, 58, 33, 0.6));
  border: 2px solid rgba(255, 215, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}

.canvas-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 1;
}

#game-canvas {
  border-radius: 16px;
  box-shadow: 0 10px 40px var(--shadow);
  border: 3px solid rgba(255, 215, 0, 0.2);
  background: #3a5a3c;
}

.feedback {
  text-align: center;
  padding: 14px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 1.05rem;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  margin-bottom: 15px;
}

.feedback.correct {
  background: rgba(39, 174, 96, 0.3);
  color: #2ecc71;
  border: 1px solid rgba(46, 204, 113, 0.5);
}

.feedback.wrong {
  background: rgba(192, 57, 43, 0.3);
  color: #e74c3c;
  border: 1px solid rgba(231, 76, 60, 0.5);
}

.feedback.hint {
  background: rgba(255, 215, 0, 0.2);
  color: var(--gold);
  border: 1px solid rgba(255, 215, 0, 0.4);
}

.controls-info {
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  margin-bottom: 20px;
}

.controls-info span {
  color: var(--sand);
  font-size: 0.9rem;
}

.result-panel {
  background: rgba(92, 58, 33, 0.9);
  border-radius: 20px;
  padding: 50px 40px;
  max-width: 550px;
  margin: 40px auto;
  text-align: center;
  box-shadow: 0 15px 50px var(--shadow);
  border: 2px solid rgba(255, 215, 0, 0.3);
}

.result-panel .trophy {
  font-size: 5rem;
  margin-bottom: 20px;
}

.result-panel h2 {
  color: var(--gold);
  font-size: 2rem;
  margin-bottom: 15px;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
  margin: 30px 0;
}

.stat-box {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 20px;
}

.stat-box .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--gold);
}

.stat-box .stat-label {
  font-size: 0.85rem;
  color: var(--sand);
  margin-top: 5px;
}

@media (max-width: 900px) {
  .info-bar {
    justify-content: center;
  }

  .game-layout-row {
    flex-direction: column;
    align-items: center;
  }

  .left-panel {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
  }

  .compass-panel,
  .touch-controls-panel {
    width: auto;
  }

  .compass-grid {
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 48px);
  }
}

@media (max-width: 768px) {
  .compass-grid {
    grid-template-columns: repeat(3, 55px);
    grid-template-rows: repeat(3, 42px);
  }

  .arrow {
    font-size: 1.1rem;
  }

  .dir-label {
    font-size: 0.5rem;
  }

  .left-panel {
    gap: 10px;
  }

  .compass-panel,
  .touch-controls-panel {
    padding: 12px;
  }

  .touch-grid {
    width: 180px;
    height: 180px;
  }

  .touch-btn {
    width: 62px;
    height: 62px;
    font-size: 1.1rem;
  }

  .touch-center {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
  }
}

@media (max-width: 600px) {
  .game-header h1 {
    font-size: 1.4rem;
  }

  .setup-panel {
    padding: 25px 20px;
  }

  .result-stats {
    grid-template-columns: 1fr;
  }

  .controls-info {
    flex-wrap: wrap;
    gap: 8px;
  }

  .controls-info span {
    font-size: 0.8rem;
  }

  .prompt-panel {
    flex-direction: column;
    text-align: center;
  }

  .left-panel {
    flex-direction: column;
    align-items: center;
  }

  .compass-panel,
  .touch-controls-panel {
    width: 100%;
    max-width: 240px;
  }

  .touch-grid {
    width: 160px;
    height: 160px;
  }

  .touch-btn {
    width: 54px;
    height: 54px;
    font-size: 1rem;
  }

  .touch-btn small {
    font-size: 0.5rem;
  }

  .touch-center {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }

  .write-input-area {
    flex-direction: column;
    align-items: stretch;
  }
}

.name-input-section {
  margin: 25px 0;
}

.name-input-section input {
  width: 100%;
  padding: 14px;
  border: 2px solid rgba(255, 215, 0, 0.3);
  border-radius: 12px;
  font-size: 1.1rem;
  text-align: center;
  background: rgba(0, 0, 0, 0.3);
  color: var(--white);
  margin-bottom: 15px;
}

.name-input-section input:focus {
  outline: none;
  border-color: var(--gold);
}

.leaderboard-panel {
  background: rgba(92, 58, 33, 0.85);
  border-radius: 16px;
  padding: 25px;
  box-shadow: 0 8px 30px var(--shadow);
  border: 2px solid rgba(255, 215, 0, 0.2);
}

.leaderboard-panel h3 {
  color: var(--gold);
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.3rem;
}

.leaderboard-list {
  list-style: none;
}

.leaderboard-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 15px;
  border-radius: 10px;
  margin-bottom: 8px;
  background: rgba(0, 0, 0, 0.2);
}

.leaderboard-entry:nth-child(1) {
  background: rgba(255, 215, 0, 0.2);
  border: 1px solid rgba(255, 215, 0, 0.4);
}

.leaderboard-entry:nth-child(2) {
  background: rgba(192, 192, 192, 0.15);
  border: 1px solid rgba(192, 192, 192, 0.3);
}

.leaderboard-entry:nth-child(3) {
  background: rgba(205, 127, 50, 0.15);
  border: 1px solid rgba(205, 127, 50, 0.3);
}

.rank {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--gold);
  font-size: 0.9rem;
}

.leaderboard-entry:nth-child(1) .rank {
  background: var(--gold);
  color: var(--dark-brown);
}

.player-info {
  flex: 1;
}

.player-name {
  font-weight: 600;
  color: var(--white);
}

.player-details {
  font-size: 0.8rem;
  color: var(--sand);
  opacity: 0.7;
}

.player-score {
  font-weight: 700;
  color: var(--gold);
  font-size: 1.1rem;
}

.confetti-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}

.confetti {
  position: absolute;
  width: 10px;
  height: 10px;
  top: -10px;
  animation: confettiFall linear forwards;
}

@keyframes confettiFall {
  to {
    top: 110vh;
    transform: rotate(720deg);
  }
}
