* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 16px;
  background: #1b1f27;
  color: #eee;
  font-family: "Segoe UI", Arial, sans-serif;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 1560px;
}

#game-layout {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

#game-layout .panel {
  flex: 0 0 250px;
  width: 250px;
}

#game-center {
  flex: 1;
  min-width: 0;
}

/* Auf schmalen Bildschirmen (z.B. Handy) wieder untereinander stapeln */
@media (max-width: 1100px) {
  #game-layout {
    flex-direction: column;
    align-items: stretch;
  }
  #game-layout .panel {
    flex: initial;
    width: auto;
  }
  #game-center {
    order: -1;
  }
}

h1 {
  text-align: center;
  margin: 0 0 12px 0;
  letter-spacing: 2px;
}

#hud {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 8px;
}

.hud-box {
  background: #2a2f3a;
  border-radius: 8px;
  padding: 8px 16px;
  min-width: 160px;
}

.hud-box h2 {
  margin: 0 0 4px 0;
  font-size: 16px;
}

.hud-center {
  flex: 1;
  text-align: center;
  background: #2a2f3a;
  border-radius: 8px;
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}

#round-info {
  font-weight: bold;
}

#turn-info {
  font-weight: bold;
  color: #ffd166;
}

#wind-strength.wind-none { color: #9aa; }

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: #87ceeb;
  border-radius: 8px;
  border: 2px solid #444;
}

#message-log {
  margin-top: 8px;
  min-height: 24px;
  text-align: center;
  font-style: italic;
  color: #9fd3ff;
}

.panel {
  background: #2a2f3a;
  border-radius: 8px;
  padding: 12px 16px;
}

.panel h3 {
  margin-top: 0;
}

.panel button {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 8px;
  background: #3d4454;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}

.panel button:hover:not(:disabled) {
  background: #4c5568;
}

.panel button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.panel button.armed {
  background: #ffd166;
  color: #1b1f27;
  font-weight: bold;
}

.price {
  float: right;
  color: #ffd166;
}

.cannon-select {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
}

/* "Kugeltyp:"-Beschriftung auf eigene Zeile, damit die Optionen sauber
   darunter stehen */
.ball-type-label {
  flex-basis: 100%;
}

.lb-me td {
  color: #ffd166;
  font-weight: bold;
}

#aim label {
  display: block;
  margin-bottom: 8px;
}

#aim input[type="range"] {
  width: 100%;
}

#fire-btn {
  background: #7a2e2e;
  font-weight: bold;
}

#fire-btn:hover:not(:disabled) {
  background: #942f2f;
}

#skip-btn {
  background: #444;
}

#gameover-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#gameover-overlay.hidden {
  display: none;
}

#gameover-box {
  background: #2a2f3a;
  padding: 32px 48px;
  border-radius: 12px;
  text-align: center;
}

#gameover-box button {
  margin-top: 16px;
  margin-right: 8px;
  padding: 10px 20px;
  font-size: 16px;
  background: #3d4454;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.corner-btn {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 30;
  width: 42px;
  height: 42px;
  font-size: 18px;
  background: #2a2f3a;
  color: #eee;
  border: 1px solid #555;
  border-radius: 50%;
  cursor: pointer;
}

.corner-btn:hover {
  background: #3d4454;
}

.corner-btn2 { left: 66px; }

.corner-select {
  position: fixed;
  top: 20px;
  left: 118px;
  z-index: 30;
  background: #2a2f3a;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
}

/* Erfolgs-Popup */
#achievement-toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-12px);
  z-index: 60;
  background: linear-gradient(135deg, #3a3320, #574a1e);
  border: 2px solid #e0b93c;
  border-radius: 10px;
  padding: 10px 20px;
  color: #ffe89a;
  font-weight: bold;
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
  opacity: 0;
  transition: opacity 0.4s, transform 0.4s;
  text-align: center;
  max-width: 80%;
}
#achievement-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#achievement-toast .ach-sub { font-weight: normal; font-size: 13px; color: #d8c89e; }

/* Erfolge-Liste */
.achievements-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.ach-card {
  display: flex;
  gap: 10px;
  align-items: center;
  background: #1f2430;
  border: 1px solid #3a3f4a;
  border-radius: 10px;
  padding: 10px 12px;
  text-align: left;
}
.ach-card.done { border-color: #e0b93c; background: #2a2820; }
.ach-icon { font-size: 22px; width: 30px; text-align: center; flex-shrink: 0; }
.ach-card.locked .ach-icon, .ach-card.locked .ach-name { opacity: 0.55; }
.ach-name { font-weight: bold; }
.ach-desc { font-size: 12px; color: #9aa; }
.ach-reward { font-size: 11px; color: #e0b93c; margin-top: 2px; }

/* gesperrte Wappen */
.crest-option.locked { cursor: not-allowed; opacity: 0.55; position: relative; }
.crest-option.locked:hover { border-color: #444; transform: none; }
.crest-option .crest-lock { font-size: 11px; color: #e0b93c; margin-top: 2px; }

/* Wiederholungs-Banner im Spiel */
#replay-banner {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 40;
  background: rgba(42,47,58,0.95);
  border: 1px solid #ffd166;
  border-radius: 8px;
  padding: 6px 12px;
  color: #ffd166;
  display: flex;
  align-items: center;
  gap: 10px;
}
#replay-banner button {
  background: #3d4454; color: #eee; border: 1px solid #555;
  border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px;
}
#gameover-achievements { color: #e0b93c; font-size: 13px; margin: 4px 0; }
#gameover-achievements div { margin: 2px 0; }

.replay-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 4px; border-bottom: 1px solid #3a3f4a;
}
.replay-row .replay-info { font-size: 13px; }
.replay-row .replay-sub { font-size: 11px; color: #9aa; }
.replay-row button {
  background: #3d4454; color: #eee; border: 1px solid #555;
  border-radius: 6px; padding: 6px 14px; cursor: pointer; flex-shrink: 0;
}

#menu-screen {
  gap: 16px;
}

.account-box {
  min-width: 360px;
}

.account-box input {
  display: block;
  width: 100%;
  margin: 8px 0;
  padding: 10px;
  background: #1f2430;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  font-size: 14px;
}

.menu-hint {
  margin-top: 8px;
  font-size: 12px;
  color: #9aa;
}

.menu-hint.error {
  color: #e06a6a;
  min-height: 16px;
}

#acc-info {
  margin: 10px 0;
  line-height: 1.6;
}

#acc-info .elo-value {
  color: #ffd166;
  font-weight: bold;
}

.menu-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
}

#search-box {
  background: #2a2f3a;
  padding: 32px 48px;
  border-radius: 12px;
  text-align: center;
  min-width: 320px;
}

.spinner {
  width: 44px;
  height: 44px;
  margin: 0 auto 14px auto;
  border: 4px solid #3d4454;
  border-top-color: #ffd166;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#menu-screen {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.menu-box {
  background: #2a2f3a;
  border-radius: 12px;
  padding: 32px 40px;
  text-align: center;
  min-width: 360px;
}

.menu-box h2 {
  margin-top: 0;
}

.menu-btn {
  display: block;
  width: 100%;
  padding: 14px;
  margin: 10px 0;
  font-size: 16px;
  background: #3d4454;
  color: #eee;
  border: 1px solid #555;
  border-radius: 8px;
  cursor: pointer;
}

.menu-btn:hover {
  background: #4c5568;
}

.menu-divider {
  margin: 18px 0 6px 0;
  color: #9aa;
  font-size: 13px;
}

.difficulty-row {
  display: flex;
  gap: 8px;
}

.difficulty-row .menu-btn {
  flex: 1;
}

.diff-btn[data-diff="easy"] { border-color: #4c8f3a; }
.diff-btn[data-diff="normal"] { border-color: #d9a441; }
.diff-btn[data-diff="hard"] { border-color: #a13a3a; }

.menu-btn.secondary {
  background: #2f3542;
  border-color: #4a5568;
}

#top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-bottom: 8px;
}

#top-bar h1 {
  margin: 0;
}

#quit-btn {
  position: absolute;
  right: 0;
  top: 0;
  padding: 8px 14px;
  background: #3d4454;
  color: #eee;
  border: 1px solid #555;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

#quit-btn:hover {
  background: #7a2e2e;
}

#castle-select-screen, #stats-screen {
  min-height: 70vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.menu-box.wide {
  min-width: 640px;
  max-width: 920px;
}

.castle-options {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: center;
  margin-top: 16px;
}

.castle-option {
  background: #1f2430;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  width: 190px;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}

.castle-option:hover {
  border-color: #ffd166;
  transform: translateY(-2px);
}

.castle-option canvas {
  display: block;
  margin: 0 auto 8px auto;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.crest-option {
  background: #1f2430;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  width: 110px;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}

.crest-option:hover {
  border-color: #ffd166;
  transform: translateY(-2px);
}

.crest-option canvas {
  display: block;
  margin: 0 auto 6px auto;
}

.castle-option-traits {
  font-size: 11px;
  color: #ffd166;
  margin-top: 4px;
  min-height: 14px;
}

.skill-option {
  background: #1f2430;
  border: 2px solid #444;
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  width: 190px;
  text-align: center;
  transition: border-color 0.15s, transform 0.15s;
}

.skill-option:hover {
  border-color: #9fd3ff;
  transform: translateY(-2px);
}

.skill-option.selected {
  border-color: #ffd166;
  background: #2c3242;
}

#skill-confirm-btn {
  margin-top: 16px;
}

.castle-option-name {
  font-weight: bold;
  margin-bottom: 2px;
}

.castle-option-desc {
  font-size: 12px;
  color: #aab;
}

#stats-table {
  margin-top: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th, .stats-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #3a3f4a;
  text-align: left;
}

.stats-table th {
  color: #9fd3ff;
}

.stat-win td:nth-child(4) { color: #6fcf6f; font-weight: bold; }
.stat-loss td:nth-child(4) { color: #e06a6a; font-weight: bold; }

#stats-back-btn {
  margin-top: 16px;
}
