:root {
  --bg: #ffffff;
  --text: #1a1a1b;
  --border: #d3d6da;
  --border-active: #878a8c;
  --key: #d3d6da;
  --correct: #6aaa64;
  --present: #c9b458;
  --absent: #787c7e;
  --on-color: #ffffff;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121213;
    --text: #f8f8f8;
    --border: #3a3a3c;
    --border-active: #565758;
    --key: #818384;
    --correct: #538d4e;
    --present: #b59f3b;
    --absent: #3a3a3c;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
}

header {
  width: 100%;
  text-align: center;
  padding: 12px 16px 8px;
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.9rem;
  letter-spacing: 0.5px;
}

.tiny {
	font-size: 0.7rem;
	opacity: 0.6;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 0.85rem;
  opacity: 0.7;
}

main {
  flex: 1;
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 16px;
  position: relative;
}

/* Invisible text field used to capture physical-keyboard input */
.capture {
  position: fixed;
  top: 0;
  left: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
  font-size: 16px;
  pointer-events: none;
}

/* Toast message */
.toast {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 10;
  white-space: nowrap;
}
.toast.visible { opacity: 1; }

/* Attempt counter */
.counter {
  margin: 28px 0 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.75;
}

/* Grid */
.grid {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  margin: 12px 0 12px;
}

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

.row.shake { animation: shake 0.5s; }

.tile {
  width: clamp(48px, 14vw, 62px);
  height: clamp(48px, 14vw, 62px);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
}

.tile.filled {
  border-color: var(--border-active);
  animation: pop 0.1s;
}

.tile.correct,
.tile.present,
.tile.absent {
  color: var(--on-color);
  border-color: transparent;
}

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

.tile.flip { animation: flip 0.6s ease both; }

/* Final result message */
.result {
  margin: 4px 0 8px;
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}

/* On-screen keyboard */
.keyboard {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1;
  min-width: 0;
  max-width: 44px;
  height: 56px;
  border: 0;
  border-radius: 4px;
  background: var(--key);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* Accent row is a bit shorter to keep the keyboard compact */
.keyboard-row.accents .key { height: 44px; }

.key.wide {
  flex: 1.6;
  max-width: 70px;
  font-size: 0.72rem;
}

.key.correct,
.key.present,
.key.absent { color: var(--on-color); }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent { background: var(--absent); }

/* Animations */
@keyframes flip {
  0%   { transform: rotateX(0); }
  50%  { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@keyframes pop {
  50% { transform: scale(1.1); }
}

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