:root{
  --bg: #ffffff;
  --text: #1a1a1b;
  --text-dim: #565758;
  --border: #d3d6da;
  --border-dark: #878a8c;

  --absent: #787c7f;
  --present: #c9b458;
  --correct: #6aaa64;

  --key-bg: #d3d6da;
  --key-text: #1a1a1b;

  --danger: #d93025;
}

*{ box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html,body{ height:100%; }
body{
  margin:0;
  background: var(--bg);
  color: var(--text);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  display:flex;
  flex-direction:column;
  align-items:center;
  min-height:100%;
}

/* ---------------- header ---------------- */
.topbar{
  width:100%;
  max-width:600px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:12px 16px;
  border-bottom:1px solid var(--border);
}
.icon-btn{
  background:none;
  border:none;
  color: var(--text);
  cursor:pointer;
  display:flex;
  align-items:center;
  justify-content:center;
  padding:4px;
  border-radius:4px;
}
.icon-btn:hover{ opacity:0.7; }
.topbar-icons{ display:flex; align-items:center; gap:14px; }
.title{
  margin:0;
  font-size:24px;
  font-weight:700;
  letter-spacing:0.06em;
  text-align:center;
  flex:1;
}
/* Kept in the same corner real Wordle puts its settings icon, but a touch
   fainter — enough that it doesn't announce itself. */
.admin-icon{ opacity:0.45; }
.admin-icon:hover, .admin-icon:focus-visible{ opacity:0.85; }

/* ---------------- toast ---------------- */
.toast{
  position:fixed;
  top:70px;
  left:50%;
  transform:translateX(-50%);
  background:var(--text);
  color:#fff;
  font-size:14px;
  font-weight:600;
  padding:10px 18px;
  border-radius:6px;
  z-index:60;
  white-space:nowrap;
  opacity:0;
  transition:opacity 150ms ease;
  pointer-events:none;
}
.toast.show{ opacity:1; }
.toast.win{ background: var(--correct); }
.toast.lose{ background: var(--danger); }

/* ---------------- board ---------------- */
main{
  width:100%;
  max-width:500px;
  display:flex;
  flex-direction:column;
  align-items:center;
  padding:20px 12px 30px;
}
.board{
  display:flex;
  flex-direction:column;
  gap:5px;
  margin-bottom:22px;
}
.row{ display:flex; gap:5px; justify-content:center; }
.tile{
  width:56px;
  height:56px;
  border:2px solid var(--border);
  border-radius:2px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:26px;
  font-weight:700;
  text-transform:uppercase;
  color:var(--text);
  transition: transform 100ms ease, background-color 150ms ease, border-color 150ms ease;
}
.tile.filled{ border-color:var(--border-dark); }
.tile.correct{ background:var(--correct); border-color:var(--correct); color:#fff; }
.tile.present{ background:var(--present); border-color:var(--present); color:#fff; }
.tile.absent{ background:var(--absent); border-color:var(--absent); color:#fff; }
.tile.flip{ animation: flip 400ms ease; }
@keyframes flip{
  0%{ transform: rotateX(0deg); }
  50%{ transform: rotateX(90deg); }
  100%{ transform: rotateX(0deg); }
}
.row.shake{ animation: shake 380ms ease; }
@keyframes shake{
  10%,90%{ transform: translateX(-1px); }
  20%,80%{ transform: translateX(2px); }
  30%,50%,70%{ transform: translateX(-4px); }
  40%,60%{ transform: translateX(4px); }
}

@media (max-width: 380px){
  .tile{ width:15vw; height:15vw; font-size:5.5vw; }
}

/* ---------------- keyboard ---------------- */
.keyboard{
  display:flex;
  flex-direction:column;
  gap:8px;
  width:100%;
  max-width:500px;
}
.krow{ display:flex; gap:6px; justify-content:center; }

.controls{
  display:flex;
  gap:22px;
  justify-content:center;
  margin-top:20px;
}
.text-btn{
  background:none;
  border:none;
  color:var(--text-dim);
  font-size:13px;
  font-weight:600;
  cursor:pointer;
  text-decoration:underline;
  text-underline-offset:3px;
  padding:4px 2px;
}
.text-btn:hover{ color:var(--text); }
.key{
  flex:1;
  max-width:43px;
  height:58px;
  border-radius:4px;
  border:none;
  background:var(--key-bg);
  color:var(--key-text);
  font-weight:700;
  font-size:13px;
  text-transform:uppercase;
  display:flex;
  align-items:center;
  justify-content:center;
  cursor:pointer;
  user-select:none;
}
.key.wide{ max-width:65px; font-size:12px; }
.key.correct{ background:var(--correct); color:#fff; }
.key.present{ background:var(--present); color:#fff; }
.key.absent{ background:var(--absent); color:#fff; }
.key:active{ filter:brightness(0.9); }

/* ---------------- modals ---------------- */
.modal-overlay{
  position:fixed;
  inset:0;
  background:rgba(0,0,0,0.5);
  display:flex;
  align-items:center;
  justify-content:center;
  z-index:80;
  padding:20px;
}
.modal-overlay[hidden]{ display:none; }
.modal-panel{
  position:relative;
  width:100%;
  max-width:320px;
  background:#fff;
  border-radius:8px;
  padding:24px;
  box-shadow:0 10px 40px rgba(0,0,0,0.25);
}
.modal-panel h2{
  margin:0 0 12px;
  font-size:17px;
  font-weight:700;
}
.modal-panel p{
  font-size:14px;
  color:var(--text-dim);
  line-height:1.5;
  margin:0 0 10px;
}
.modal-panel label{
  display:block;
  font-size:12.5px;
  color:var(--text-dim);
  margin-bottom:14px;
}
.modal-panel input{
  display:block;
  width:100%;
  margin-top:6px;
  padding:9px 10px;
  border-radius:4px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  font-size:14px;
  font-family:inherit;
}
.modal-panel input:focus{ outline:2px solid #1a1a1b; outline-offset:-1px; }
.modal-hint{ font-size:11.5px; color:var(--text-dim); margin:-8px 0 12px; }
.modal-error{ color:var(--danger); font-size:12px; min-height:16px; margin:-6px 0 10px; }
.modal-close{
  position:absolute;
  top:8px;
  right:10px;
  background:none;
  border:none;
  color:var(--text-dim);
  font-size:20px;
  line-height:1;
  cursor:pointer;
  padding:4px;
}
.modal-close:hover{ color:var(--text); }

.btn-primary{
  background:var(--text);
  color:#fff;
  border:none;
  border-radius:4px;
  padding:10px 16px;
  font-size:14px;
  font-weight:700;
  cursor:pointer;
  width:100%;
}
.btn-primary:hover{ opacity:0.85; }

.modal-actions{
  display:flex;
  gap:10px;
  margin-top:4px;
}
.modal-actions button{ flex:1; }
.btn-secondary{
  background:#fff;
  color:var(--text);
  border:1px solid var(--border-dark);
  border-radius:4px;
  padding:10px 16px;
  font-size:14px;
  font-weight:700;
  cursor:pointer;
}
.btn-secondary:hover{ background:var(--key-bg); }
.btn-danger{
  background:var(--danger);
  color:#fff;
  border:none;
  border-radius:4px;
  padding:10px 16px;
  font-size:14px;
  font-weight:700;
  cursor:pointer;
}
.btn-danger:hover{ opacity:0.85; }

.legend{ list-style:none; padding:0; margin:12px 0 0; }
.legend li{
  display:flex;
  align-items:center;
  gap:10px;
  font-size:13.5px;
  color:var(--text);
  margin-bottom:8px;
}
.legend-tile{
  width:30px;
  height:30px;
  min-width:30px;
  display:flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
  color:#fff;
  border-radius:2px;
}
.legend-tile.correct{ background:var(--correct); }
.legend-tile.present{ background:var(--present); }
.legend-tile.absent{ background:var(--absent); }
