:root {
  --bg: #faf9f6;
  --ink: #1f1d1a;
  --tile: #efece5;
  --tile-selected: #4a453d;
  --accent: #6b5cd6;
  --yellow: #f5d95e;
  --green: #a0d16d;
  --blue: #8ab8f0;
  --purple: #c297e2;
}

* { box-sizing: border-box; }

body {
  margin: 0 auto;
  max-width: 520px;
  padding: 12px 12px 40px;
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 8px;
}

h1 { font-size: 1.5rem; margin: 8px 0; letter-spacing: .15em; }

#help-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: none;
  font-weight: 700;
  cursor: pointer;
}

#tagline { font-size: .85rem; color: #6a655c; }

#board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.tile {
  aspect-ratio: 5 / 3;
  border: none;
  border-radius: 8px;
  background: var(--tile);
  font-weight: 700;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  padding: 2px;
  word-break: keep-all;
  transition: transform .08s;
}
.tile:active { transform: scale(.95); }
.tile.long { font-size: .78rem; }
.tile.vlong { font-size: .65rem; }
.tile.selected { background: var(--tile-selected); color: #fff; }
.tile.shake { animation: shake .3s; }

@keyframes shake {
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.solved-group {
  border-radius: 8px;
  padding: 10px;
  margin: 0 0 8px;
  text-align: center;
  animation: pop .25s;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } }
.solved-group b { display: block; }
.solved-group span { font-size: .9rem; }
.solved-group.yellow { background: var(--yellow); }
.solved-group.green { background: var(--green); }
.solved-group.blue { background: var(--blue); }
.solved-group.purple { background: var(--purple); }

#mistakes { font-size: .9rem; display: flex; gap: 8px; align-items: center; }
#dots span {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #cfc9bd;
  margin-right: 4px;
}
#dots span.used { background: #e03131; }

#controls { display: flex; gap: 8px; margin: 14px 0; }
#controls button {
  flex: 1;
  padding: 12px 4px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: none;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}
#controls button:disabled { opacity: .35; cursor: default; }
#submit:not(:disabled) { background: var(--ink); color: #fff; }

#toast {
  position: fixed;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 8px 20px;
  border-radius: 999px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
  z-index: 10;
}
#toast.show { opacity: 1; }

dialog {
  border: none;
  border-radius: 14px;
  max-width: 400px;
  width: calc(100% - 48px);
  padding: 20px;
  font-family: inherit;
}
dialog::backdrop { background: rgba(30, 28, 24, .55); }
dialog h2 { margin-top: 0; }
dialog li { margin-bottom: 6px; font-size: .92rem; }
dialog button {
  padding: 10px 20px;
  border-radius: 999px;
  border: 1.5px solid var(--ink);
  background: none;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

.c { padding: 1px 6px; border-radius: 4px; font-size: .85em; white-space: nowrap; }
.c.y { background: var(--yellow); } .c.g { background: var(--green); }
.c.b { background: var(--blue); } .c.p { background: var(--purple); }

#emoji-grid {
  font-size: 1.3rem;
  line-height: 1.4;
  text-align: center;
  background: #f4f2ec;
  border-radius: 8px;
  padding: 10px;
}

#result-actions { display: flex; gap: 8px; margin-bottom: 14px; }
#result-actions button { flex: 1; }
#share-x { background: var(--ink); color: #fff; }

#stats {
  display: flex;
  justify-content: space-around;
  text-align: center;
  margin-bottom: 14px;
}
#stats b { font-size: 1.4rem; display: block; }
#stats small { color: #6a655c; }

footer { margin-top: 24px; text-align: center; }
footer a { color: var(--accent); font-size: .85rem; }

#loading { text-align: center; color: #6a655c; }
