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

body {
  overflow: hidden;
  background: #1a1a2e;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#container {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Title Overlay */
#title-overlay {
  position: absolute;
  top: 15px;
  left: 50%;
  transform: translateX(-50%);
  font-family: 'Rye', cursive;
  font-size: 46px;
  color: #ffd700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8), 0 0 10px rgba(255, 215, 0, 0.3);
  pointer-events: none;
  white-space: nowrap;
  letter-spacing: 2px;
  z-index: 5;
}

/* Settings Button */
#btn-settings {
  background: #546e7a;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: 'Rye', cursive;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#btn-settings:hover {
  background: #78909c;
  transform: translateY(-1px);
}

/* Settings Menu */
#settings-menu {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.9);
  border: 2px solid #ffd700;
  border-radius: 12px;
  padding: 30px;
  color: #fff;
  z-index: 100;
  min-width: 300px;
  font-family: 'Rye', cursive;
  text-align: center;
}

#settings-menu h3 {
  color: #ffd700;
  margin-bottom: 20px;
  font-size: 24px;
}

.setting-item {
  margin-bottom: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.setting-item label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
}

.setting-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  cursor: pointer;
}

#btn-close-settings {
  background: #ffd700;
  color: #1a1a2e;
  border: none;
  padding: 10px 24px;
  border-radius: 6px;
  font-family: 'Rye', cursive;
  font-size: 16px;
  cursor: pointer;
}

#btn-close-settings:hover {
  background: #ffca28;
}

/* Set Target Modal */
#target-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
}

#target-modal-box {
  background: #1a1a2e;
  border: 2px solid #ffd700;
  border-radius: 16px;
  padding: 40px 50px;
  text-align: center;
  font-family: 'Rye', cursive;
  color: #fff;
}

#target-modal-box h3 {
  color: #ffd700;
  font-size: 32px;
  margin-bottom: 12px;
}

#target-modal-box p {
  font-size: 16px;
  color: #aaa;
  margin-bottom: 24px;
}

#target-input-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 20px;
}

.target-input {
  width: 60px;
  height: 60px;
  text-align: center;
  font-size: 32px;
  font-family: 'Rye', cursive;
  border: 2px solid #546e7a;
  border-radius: 10px;
  background: #263238;
  color: #ffd700;
  outline: none;
}

.target-input:focus {
  border-color: #ffd700;
  box-shadow: 0 0 8px rgba(255, 215, 0, 0.4);
}

#target-modal-error {
  color: #e53935;
  font-size: 14px;
  margin-bottom: 16px;
}

#target-modal-buttons {
  display: flex;
  gap: 16px;
  justify-content: center;
}

#btn-target-ok, #btn-target-cancel {
  padding: 12px 32px;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-family: 'Rye', cursive;
  cursor: pointer;
}

#btn-target-ok {
  background: #ffd700;
  color: #1a1a2e;
}
#btn-target-ok:hover { background: #ffca28; }

#btn-target-cancel {
  background: #546e7a;
  color: #fff;
}
#btn-target-cancel:hover { background: #78909c; }

#btn-set-target {
  background: #00897b;
  color: #fff;
}
#btn-set-target:hover { background: #00796b; }

#btn-instructions {
  background: #5c6bc0;
  color: #fff;
}
#btn-instructions:hover { background: #3f51b5; }

/* Instructions Modal */
#instructions-modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  z-index: 100;
}

#instructions-box {
  background: #1a1a2e;
  border: 2px solid #ffd700;
  border-radius: 16px;
  padding: 36px 44px;
  max-width: 520px;
  font-family: 'Rye', cursive;
  color: #ddd;
  font-size: 14px;
  line-height: 1.6;
}

#instructions-box h3 {
  color: #ffd700;
  font-size: 28px;
  margin-bottom: 16px;
  text-align: center;
}

#instructions-box p {
  margin-bottom: 12px;
}

#instructions-box ul {
  margin: 0 0 14px 20px;
}

#instructions-box li {
  margin-bottom: 6px;
}

#instructions-box .instructions-link {
  text-align: center;
  margin-bottom: 18px;
}

#instructions-box .instructions-link a {
  color: #64b5f6;
  text-decoration: none;
}

#instructions-box .instructions-link a:hover {
  text-decoration: underline;
}

#btn-close-instructions {
  display: block;
  margin: 0 auto;
  background: #ffd700;
  color: #1a1a2e;
  border: none;
  padding: 10px 28px;
  border-radius: 6px;
  font-family: 'Rye', cursive;
  font-size: 16px;
  cursor: pointer;
}

#btn-close-instructions:hover {
  background: #ffca28;
}

/* HUD */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 25px;
  pointer-events: none;
  font-family: 'Rye', cursive;
}

#target-panel {
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  padding: 10px 16px;
}

#target-label {
  color: #ffd700;
  font-size: 14px;
  text-transform: none;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

#target-cars {
  display: flex;
  gap: 6px;
}

.target-car {
  width: 36px;
  height: 24px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: normal;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  border: 2px solid rgba(255,255,255,0.3);
}

#hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

#move-counter {
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  padding: 8px 14px;
  color: #ffd700;
  font-size: 16px;
}

#status-line {
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  padding: 8px 14px;
  color: #ccc;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.status-label {
  color: #ffd700;
  font-size: 11px;
  min-width: 58px;
  text-align: right;
}

.status-chips {
  display: flex;
  gap: 4px;
}

.status-chip {
  width: 26px;
  height: 18px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.3);
}

.status-empty {
  color: #666;
  font-size: 11px;
  font-style: italic;
}

/* Controls */
#controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 10px;
  padding: 10px 16px;
  font-family: 'Rye', cursive;
}

#move-buttons, #action-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

#move-buttons, #action-buttons {
  padding-right: 16px;
  border-right: 1px solid rgba(255, 215, 0, 0.3);
}

.control-label {
  color: #ffd700;
  font-size: 14px;
  margin-right: 4px;
}

#controls button {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-family: 'Rye', cursive;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
}

.btn-move {
  background: #546e7a;
  color: #fff;
  min-width: 38px;
}
.btn-move:hover { background: #78909c; }
.btn-move:disabled {
  background: #ffd700;
  color: #1a1a2e;
  cursor: default;
  opacity: 1;
}
.btn-move:disabled:hover { transform: none; }

#controls button:hover {
  transform: translateY(-1px);
}

#controls button:active {
  transform: translateY(0);
}

#btn-couple {
  background: #4caf50;
  color: #fff;
}
#btn-couple:hover { background: #45a049; }

#btn-decouple {
  background: #f44336;
  color: #fff;
}
#btn-decouple:hover { background: #e53935; }

#btn-solve {
  background: #7b1fa2;
  color: #fff;
}
#btn-solve:hover { background: #6a1b9a; }

#btn-retry {
  background: #ff9800;
  color: #fff;
}
#btn-retry:hover { background: #f57c00; }

#btn-reset {
  background: #2196f3;
  color: #fff;
}
#btn-reset:hover { background: #1e88e5; }

/* Victory overlay */
#victory {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.175);
  z-index: 10;
}

#victory-text {
  font-family: 'Rye', cursive;
  font-size: 84px;
  color: #ffd700;
  text-shadow: 0 0 20px rgba(255, 215, 0, 0.5);
  margin-bottom: 20px;
}

#victory-moves {
  font-family: 'Rye', cursive;
  font-size: 24px;
  color: #fff;
  margin-bottom: 30px;
}

#victory-buttons {
  display: flex;
  gap: 16px;
}

#btn-replay-level, #btn-new-game {
  padding: 14px 32px;
  border: none;
  border-radius: 8px;
  font-size: 20px;
  font-family: 'Rye', cursive;
  cursor: pointer;
}

#btn-replay-level {
  background: #ff9800;
  color: #fff;
}
#btn-replay-level:hover { background: #f57c00; }

#btn-new-game {
  background: #ffd700;
  color: #1a1a2e;
}
#btn-new-game:hover { background: #ffca28; }

/* Error toast */
#error-toast {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(244, 67, 54, 0.9);
  color: #fff;
  padding: 8px 20px;
  border-radius: 6px;
  font-size: 14px;
  transition: opacity 0.3s;
  z-index: 5;
}

/* Conductor View PIP */
#conductor-pip {
  position: absolute;
  bottom: 80px;
  left: 20px;
  width: 420px;
  height: 315px;
  border: 2px solid #ffd700;
  border-radius: 6px;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
}

#conductor-pip::after {
  content: 'Conductor View';
  position: absolute;
  top: -20px;
  left: 6px;
  font-family: 'Rye', cursive;
  font-size: 11px;
  color: #ffd700;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.hidden {
  display: none !important;
}
