:root {
  --bg: #ffffff;
  --text: #000000;
  --border: #d3d6da;
  --border-filled: #878a8c;
  --key-bg: #d3d6da;
  --key-text: #000000;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --toast-bg: #121213;
  --toast-text: #ffffff;
  --modal-bg: #ffffff;
  --overlay: rgba(255, 255, 255, 0.5);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --text: #ffffff;
    --border: #3a3a3c;
    --border-filled: #565758;
    --key-bg: #818384;
    --key-text: #ffffff;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
    --toast-bg: #ffffff;
    --toast-text: #121213;
    --modal-bg: #121213;
    --overlay: rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Clear Sans", "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 65px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

h1 {
  margin: 0;
  font-family: "Karnak Condensed", Georgia, "Times New Roman", serif;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.icon-button {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  display: flex;
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  min-height: 0;
}

#board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  padding: 10px;
  width: min(350px, 100vw);
  height: min(420px, calc(100% - 20px));
  aspect-ratio: 5 / 6;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
}

.tile {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  border: 2px solid var(--border);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}

.tile[data-state="tbd"] {
  border-color: var(--border-filled);
  animation: pop 100ms;
}

.tile[data-state="correct"],
.tile[data-state="present"],
.tile[data-state="absent"] {
  border: none;
  color: #ffffff;
}

.tile[data-state="correct"] { background: var(--correct); }
.tile[data-state="present"] { background: var(--present); }
.tile[data-state="absent"] { background: var(--absent); }

.tile.flip-in {
  animation: flip-in 250ms ease-in forwards;
}

.tile.flip-out {
  animation: flip-out 250ms ease-in;
}

.tile.bounce {
  animation: bounce 1000ms;
}

.board-row.shake {
  animation: shake 600ms;
}

@keyframes pop {
  from { transform: scale(0.8); opacity: 0; }
  40% { transform: scale(1.1); opacity: 1; }
}

@keyframes flip-in {
  from { transform: rotateX(0); }
  to { transform: rotateX(-90deg); }
}

@keyframes flip-out {
  from { transform: rotateX(-90deg); }
  to { transform: rotateX(0); }
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

@keyframes bounce {
  0%, 20% { transform: translateY(0); }
  40% { transform: translateY(-30px); }
  50% { transform: translateY(5px); }
  60% { transform: translateY(-15px); }
  80% { transform: translateY(2px); }
  100% { transform: translateY(0); }
}

#keyboard {
  width: 100%;
  max-width: 500px;
  margin: 0 auto 8px;
  padding: 0 8px;
  flex-shrink: 0;
  user-select: none;
}

#keyboard .row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  touch-action: manipulation;
}

#keyboard button {
  flex: 1;
  height: 58px;
  border: 0;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  font-family: inherit;
  font-size: 1.25em;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  transition: background-color 100ms;
}

#keyboard button.wide {
  flex: 1.5;
  font-size: 12px;
}

#keyboard .spacer {
  flex: 0.5;
}

#keyboard button[data-state="correct"] { background: var(--correct); color: #fff; }
#keyboard button[data-state="present"] { background: var(--present); color: #fff; }
#keyboard button[data-state="absent"] { background: var(--absent); color: #fff; }

#toasts {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 16px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  transition: opacity 300ms;
}

.toast.fade {
  opacity: 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 200;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  position: relative;
  width: min(500px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--modal-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 23px rgba(0, 0, 0, 0.2);
  padding: 24px 28px;
  animation: slide-in 200ms ease-out;
  line-height: 1.6;
}

@keyframes slide-in {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal h2 {
  margin: 0 0 12px;
  font-family: "Karnak Condensed", Georgia, serif;
  font-size: 28px;
}

.modal .close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 28px;
  cursor: pointer;
}

.modal ul {
  list-style: none;
  padding: 0;
}

.modal li {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.mini {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 32px;
  height: 32px;
  color: #fff;
  font-weight: 700;
}

.mini.correct { background: var(--correct); }
.mini.present { background: var(--present); }
.mini.absent { background: var(--absent); }

.evil {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

#result-candidates {
  font-family: ui-monospace, Menlo, monospace;
  font-size: 14px;
  text-transform: uppercase;
  color: var(--border-filled);
  word-break: break-word;
}

.modal-buttons {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.primary {
  flex: 1;
  height: 48px;
  border: none;
  border-radius: 24px;
  background: var(--correct);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}
