/* ===== Light Mode (Standard) ===== */
table.sudoku {
  border-collapse: collapse;
  margin: auto;
}

td.cell {
  width: 40px;
  height: 40px;
  text-align: center;
  vertical-align: middle;
  font-size: 24px;
  user-select: none;
  border: 1px solid #999; /* Default dünner Rahmen */
  cursor: pointer;
  background-color: #fff;
  color: #000;
}

td.border-top-outer    { border-top: 3px solid black !important; }
td.border-left-outer   { border-left: 3px solid black !important; }
td.border-right-outer  { border-right: 3px solid black !important; }
td.border-bottom-outer { border-bottom: 3px solid black !important; }
td.border-right-block  { border-right: 3px solid black !important; }
td.border-bottom-block { border-bottom: 3px solid black !important; }

/* Hervorhebung der selektierten Zelle */
td.cell.selected {
  outline: 3px solid #2196F3;
  background-color: #d0e7ff;
  cursor: pointer;
}

/* Richtig / Falsch */
td.cell.correct {
  background-color: #ccffcc;
  border: 2px solid #00ff00;
  outline: none;
  transition: background-color 0.5s ease;
}
td.cell.incorrect {
  background-color: #ffcccc;
  border: 2px solid #ff0000;
  transition: background-color 0.5s ease;
}

/* ===== Fehleranzeige ===== */
#error-status {
  margin: 15px 0;
  color: #ff0000;
  font-weight: bold;
  font-size: 1.2em;
  transition: color 0.3s ease;
}
#error-status.error-flash {
  color: #ff5555;
  animation: flashRed 0.5s ease;
}
@keyframes flashRed {
  0%, 100% { color: #ff0000; }
  50% { color: #ffaaaa; }
}

/* ===== Allgemeines Layout ===== */
body {
  font-family: Arial, sans-serif;
  text-align: center;
  margin: 20px;
}
.top-controls, .bottom-controls {
  margin: 10px auto;
  max-width: 400px;
}
.top-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
form { margin-bottom: 10px; }
label {
  margin-right: 8px;
  font-weight: bold;
}
button, select {
  font-size: 1rem;
  padding: 5px 10px;
  margin: 0 5px 10px 0;
}
.top-controls button,
.bottom-controls button,
.top-controls select,
.bottom-controls select {
  font-size: 0.9rem;
  padding: 4px 8px;
}

/* ===== Auswahl-Pad ===== */
#selection-pad {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
@media (max-width: 480px) {
  .pad-btn {
    font-size: 1.2rem;
    padding: 6px 10px;
  }
}
.pad-btn {
  font-size: 40px;
  width: 64px;
  height: 64px;
  border-radius: 10px;
  border: 1px solid #888;
  cursor: pointer;
  margin: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pad-btn:active { transform: scale(0.95); }

/* ===== Dialog ===== */
.dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.dialog.hidden { display: none; }
.dialog-box {
  background: #fff;
  padding: 1em;
  border-radius: 10px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}

/* ===== Kleine Bildschirme ===== */
@media (max-width: 480px) {
  .top-controls,
  .bottom-controls { max-width: 95%; }

  .top-controls form,
  .bottom-controls form { margin-bottom: 6px; }

  .top-controls { gap: 4px; }

  label { font-size: 0.85rem; }

  button, select {
    font-size: 0.85rem;
    padding: 3px 6px;
  }
}

/* ===== Hilfe-Button und Hilfe-Popup ===== */
.control-with-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-btn {
  font-size: 0.9rem;
  padding: 2px 6px;
  border-radius: 50%;
  border: 1px solid #888;
  background: transparent;
  cursor: pointer;
  user-select: none;
}

.help-box {
  position: relative;
  bottom: 120%;               /* Box öffnet nach oben */
  right: 0;
  background: #fff;
  color: #000;
  border: 1px solid #aaa;
  border-radius: 8px;
  padding: 10px;
  max-width: 260px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  font-size: 0.9rem;
  text-align: left;
  z-index: 1000;
  display: none;
  white-space: normal;
}
.help-box.visible { display: block; }

/* Pfeil nach unten */
.help-box::after {
  content: "";
  position: absolute;
  top: 100%;
  right: 12px;
  border-width: 8px;
  border-style: solid;
  border-color: #fff transparent transparent transparent;
}

.help-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
  padding: 0;
  user-select: none;
}
.help-close:hover { color: #000; }

.help-box .warning {
  color: #b33939;
  background-color: #f8d7da;
  border: 1px solid #f5c6cb;
  padding: 6px 10px;
  border-radius: 5px;
  margin: 10px 0;
  font-weight: bold;
  font-size: 0.9rem;
}

/* ===== Wake-Lock-Button ===== */
#wakeToggle {
  background-color: #f0f0f0;
  transition: background-color 0.3s ease;
}
#wakeToggle:hover,
#wakeToggle:focus {
  background-color: #a8d0a8;
  outline: none;
}

/* ===== Hinweis auf offene Spiele (cross-hint) ===== */
.cross-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff8d6;
  border: 1px solid #e0cf7a;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 8px 0;
  font-size: 0.95em;
}
.cross-hint.hidden { display: none; }
.cross-hint a { font-weight: bold; }
.cross-hint button {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}

/* ===================================================================
   Dark Mode
   =================================================================== */

body.dark {
  background-color: #121212;
  color: #e0e0e0;
  color-scheme: dark;                         /* Buttons, Auswahlfelder */
}
:root:has(body.dark) { color-scheme: dark; }  /* Seiten-Scrollbalken */

body.dark table.sudoku { border-color: #666; }

body.dark td.cell {
  background-color: #222;
  color: #eee;
  border: 1px solid #555;
  cursor: pointer;
}

body.dark td.border-top-outer,
body.dark td.border-left-outer,
body.dark td.border-right-outer,
body.dark td.border-bottom-outer,
body.dark td.border-right-block,
body.dark td.border-bottom-block {
  border-color: #888 !important;
}

body.dark td.cell.selected {
  outline: 3px solid #64b5f6;
  background-color: #335577;
}

/* Richtig/Falsch (sonst überschreibt "body.dark td.cell" sie) */
body.dark td.cell.correct   { background-color: #1e4d2b; border: 2px solid #4caf50; }
body.dark td.cell.incorrect { background-color: #5c2020; border: 2px solid #ef5350; }

/* Links */
body.dark a { color: #8ab4f8; }
body.dark a:visited { color: #c9a7f5; }

/* Dialog */
body.dark .dialog-box {
  background: #2a2a2a;
  color: #eee;
  box-shadow: 0 10px 30px rgba(0,0,0,.8);
}

/* Hilfe-Popup */
body.dark .help-box {
  background: #222;
  color: #eee;
  border-color: #666;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}
body.dark .help-box::after {
  border-color: #222 transparent transparent transparent;
}
body.dark .help-close { color: #ccc; }
body.dark .help-close:hover { color: #fff; }
body.dark .help-box .warning {
  color: #f5b5ba;
  background-color: #4a2326;
  border-color: #7a3a3f;
}

/* Wake-Lock-Button */
body.dark #wakeToggle { background-color: #3a3a3a; }
body.dark #wakeToggle:hover,
body.dark #wakeToggle:focus { background-color: #2e5a2e; }

/* Hinweis auf offene Spiele */
body.dark .cross-hint {
  background: #3a3620;
  border-color: #6b6230;
  color: #eee;
}
