/* ── Reset & variables ───────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --card:      #21262d;
  --border:    #30363d;
  --accent:    #58a6ff;
  --success:   #3fb950;
  --warning:   #d29922;
  --danger:    #f85149;
  --text:      #c9d1d9;
  --dim:       #6e7681;

  --gallows:   #c9d1d9;
  --rope:      #996633;
  --body-col:  #e06c75;

  --bronze:    #cd7f32;
  --silver:    #a8a8a8;
  --gold:      #ffd700;
  --platinum:  #e0e0f0;
  --diamond:   #7df9ff;
}

html, body {
  height: 100%;
  font-family: 'Courier New', Courier, monospace;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

h1 {
  font-size: 1.25rem;
  letter-spacing: 0.18em;
  color: var(--accent);
  white-space: nowrap;
}

.header-center {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.field-label {
  font-size: 0.75rem;
  color: var(--dim);
  white-space: nowrap;
}

#username-input {
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.85rem;
  width: 200px;
}

#username-input:focus {
  outline: none;
  border-color: var(--accent);
}

.header-right {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn, button {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.35rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn:hover, button:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn-primary {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary:hover {
  background: rgba(88,166,255,0.08);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ── Main layout ─────────────────────────────────────────────────────────── */

main {
  display: grid;
  grid-template-columns: 210px 1fr 195px;
  flex: 1;
  overflow: hidden;
}

aside {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 0.9rem;
  overflow-y: auto;
}

#stats-panel {
  border-right: none;
  border-left: 1px solid var(--border);
}

aside h2 {
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.6rem;
}

.section-gap { margin-top: 1.25rem; }

/* ── Trophy panel ────────────────────────────────────────────────────────── */

.t-category { margin-bottom: 0.9rem; }

.t-category-title {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 0.35rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid var(--border);
}

.t-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.4rem;
  border-radius: 5px;
  margin-bottom: 0.2rem;
  border: 1px solid transparent;
  opacity: 0.28;
  transition: opacity 0.4s, border-color 0.4s, background 0.4s;
  cursor: default;
}

.t-item[title]:hover::after {
  content: attr(title);
}

.t-item.earned          { opacity: 1; }
.t-item.bronze          { border-color: var(--bronze);   background: rgba(205,127,50,0.07); }
.t-item.silver          { border-color: var(--silver);   background: rgba(168,168,168,0.07); }
.t-item.gold            { border-color: var(--gold);     background: rgba(255,215,0,0.07); }
.t-item.platinum        { border-color: var(--platinum); background: rgba(224,224,240,0.07); }
.t-item.diamond         { border-color: var(--diamond);  background: rgba(125,249,255,0.07); }

.t-icon { font-size: 1rem; line-height: 1; }

.t-info { display: flex; flex-direction: column; }
.t-name { font-size: 0.74rem; font-weight: bold; }
.t-desc { font-size: 0.62rem; color: var(--dim); }

/* ── Game area ───────────────────────────────────────────────────────────── */

#game-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.9rem 1.5rem;
  gap: 0.6rem;
  overflow-y: auto;
}

#game-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

#game-title {
  font-size: 0.78rem;
  color: var(--dim);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Gallows SVG ─────────────────────────────────────────────────────────── */

#gallows-wrapper {
  width: 210px;
  height: 245px;
  flex-shrink: 0;
}

#gallows { width: 100%; height: 100%; }

.gp {
  stroke: var(--gallows);
  stroke-width: 3.5;
  stroke-linecap: round;
  fill: none;
}

.gp.rope {
  stroke: var(--rope);
  stroke-width: 2.5;
}

.bp {
  stroke: var(--body-col);
  stroke-width: 3.5;
  stroke-linecap: round;
  fill: none;
  opacity: 0;
  transition: opacity 0.45s ease;
}

#p-head { fill: none; }

.bp.show { opacity: 1; }

/* Shake on wrong guess */
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-5px); }
  40%     { transform: translateX(5px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}

#gallows-wrapper.shake { animation: shake 0.4s ease; }

/* ── Word display ────────────────────────────────────────────────────────── */

#word-display {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: center;
  min-height: 3rem;
  align-items: flex-end;
}

.ls {
  width: 1.9rem;
  height: 2.6rem;
  border-bottom: 2.5px solid var(--dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: bold;
  letter-spacing: 0.02em;
  transition: color 0.3s, border-color 0.3s;
}

.ls.revealed { color: var(--success); border-color: var(--success); }
.ls.missed   { color: var(--danger);  border-color: var(--danger); }

/* ── Wrong / hint lines ──────────────────────────────────────────────────── */

#wrong-line {
  font-size: 0.8rem;
  color: var(--danger);
  min-height: 1.1rem;
  letter-spacing: 0.05em;
}

#wrong-count {
  color: var(--dim);
  margin-left: 0.4rem;
  font-size: 0.75rem;
}

#word-hint {
  font-size: 0.75rem;
  color: var(--dim);
}

/* ── Status message ──────────────────────────────────────────────────────── */

#status-msg {
  min-height: 1.4rem;
  font-size: 0.95rem;
  font-weight: bold;
  text-align: center;
  letter-spacing: 0.04em;
}

#status-msg.win  { color: var(--success); }
#status-msg.lose { color: var(--danger); }
#status-msg.info { color: var(--accent); }

/* ── Keyboard ────────────────────────────────────────────────────────────── */

#keyboard {
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem;
  justify-content: center;
  max-width: 410px;
}

.key {
  width: 1.9rem;
  height: 1.9rem;
  padding: 0;
  font-size: 0.78rem;
  font-weight: bold;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.12s, background 0.12s, color 0.12s, opacity 0.12s;
}

.key:hover:not(:disabled):not(.correct):not(.wrong) {
  border-color: var(--accent);
  color: var(--accent);
}

.key.correct {
  background: rgba(63,185,80,0.18);
  border-color: var(--success);
  color: var(--success);
  cursor: default;
}

.key.wrong {
  background: rgba(248,81,73,0.08);
  border-color: transparent;
  color: var(--dim);
  opacity: 0.5;
  cursor: default;
}

/* ── Action buttons ──────────────────────────────────────────────────────── */

#action-buttons {
  display: flex;
  gap: 0.6rem;
}

/* ── Stats panel ─────────────────────────────────────────────────────────── */

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.28rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
}

.stat-row:last-child { border-bottom: none; }

.stat-label { color: var(--dim); }
.stat-value { font-weight: bold; }

.stat-section-label {
  font-size: 0.68rem;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0.65rem 0 0.25rem;
}

/* ── History ─────────────────────────────────────────────────────────────── */

.hist-item {
  font-size: 0.72rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--dim);
  line-height: 1.5;
}

.hist-result        { font-weight: bold; font-size: 0.74rem; }
.hist-result.win    { color: var(--success); }
.hist-result.lose   { color: var(--danger); }

/* ── Trophy toast ────────────────────────────────────────────────────────── */

#trophy-toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  background: var(--card);
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 0.7rem 1rem;
  z-index: 200;
  box-shadow: 0 6px 24px rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 270px;
  animation: toast-in 0.35s ease;
}

#trophy-toast.hidden { display: none; }

#toast-icon { font-size: 2rem; line-height: 1; }
#toast-name { font-weight: bold; font-size: 0.88rem; color: var(--gold); margin-bottom: 0.15rem; }
#toast-desc { font-size: 0.72rem; color: var(--dim); }

@keyframes toast-in {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* ── Touch & mobile ──────────────────────────────────────────────────────── */

.btn, button, .key {
  touch-action: manipulation;
}

@media (max-width: 700px) {
  body { overflow-y: auto; }

  header {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.6rem 0.9rem;
  }

  h1 { font-size: 1rem; }

  .header-center { width: 100%; order: 2; }
  #username-input { width: 100%; }

  .header-right { order: 3; width: 100%; }

  main {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }

  #game-area    { order: 1; }
  #stats-panel  { order: 2; border-left: none; border-top: 1px solid var(--border); }
  #trophy-panel { order: 3; border-right: none; border-top: 1px solid var(--border); }

  .key {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 0.9rem;
  }

  #keyboard { max-width: 100%; padding: 0 0.5rem; }
}
