:root {
  --bg: #121213;
  --fg: #ffffff;
  --tile-border: #3a3a3c;
  --tile-border-filled: #565758;
  --key-bg: #818384;
  --key-fg: #ffffff;
  --correct: #538d4e;
  --present: #b59f3b;
  --absent: #3a3a3c;
  --modal-bg: #1a1a1b;
  --max-w: 500px;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

.header {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  border-bottom: 1px solid var(--tile-border);
  padding: 8px 12px;
  flex: 0 0 auto;
}

.title {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 4px;
  margin: 0;
}

.icon-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--fg);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 8px;
  min-height: 0;
}

.message {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 6px;
}

.message .toast {
  background: var(--fg);
  color: #000;
  padding: 6px 12px;
  border-radius: 4px;
  font-weight: 700;
  font-size: 14px;
  animation: fade 0.15s ease-in;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Board */
.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 5px;
  flex: 1 1 auto;
  width: 100%;
  max-width: 330px;
  padding: 10px 0;
  min-height: 0;
}

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

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--tile-border);
  font-size: clamp(20px, 7vw, 32px);
  font-weight: 700;
  text-transform: uppercase;
  aspect-ratio: 1 / 1;
  color: var(--fg);
  transition: transform 0.08s ease;
}

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

@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

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

.tile.reveal { animation: flip 0.5s ease forwards; }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

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

/* Keyboard */
.keyboard {
  width: 100%;
  max-width: var(--max-w);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 4px 12px;
  flex: 0 0 auto;
}

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

.key {
  flex: 1 1 auto;
  height: 52px;
  min-width: 0;
  border: none;
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-fg);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.key.wide { flex: 1.5 1 auto; font-size: 11px; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: var(--absent); }
.key:active { opacity: 0.7; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal-overlay[hidden] { display: none; }

.modal {
  position: relative;
  background: var(--modal-bg);
  border: 1px solid var(--tile-border);
  border-radius: 8px;
  padding: 24px 20px;
  width: min(90vw, 360px);
  text-align: center;
}

.modal h2 { margin: 0 0 16px; font-size: 18px; letter-spacing: 1px; }

.modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  background: none;
  border: none;
  color: var(--fg);
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}

.stats-grid {
  display: flex;
  justify-content: space-around;
  margin-bottom: 12px;
}
.stat-num { font-size: 30px; font-weight: 700; }
.stat-label { font-size: 11px; opacity: 0.8; }

.stats-summary { font-size: 15px; min-height: 20px; font-weight: 600; }
.stats-note { font-size: 12px; opacity: 0.6; }
