:root {
  --bgColor: #2e3440;
  --textPrimary: #e5e9f0;
  --textSecondary: #81a1c1;
  --buttonBorderColor: #e5e9f0;
  --fontSize: 24px;
  --fontFamily: monospace;
  --errorColor: #ff5f7a;
  --drawerWidth: min(360px, 92vw);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--fontFamily);
  font-size: var(--fontSize);
  color: var(--textPrimary);
  background: var(--bgColor);
}

main {
  width: min(96%, 1180px);
  margin: 12px auto;
}

.topbar {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.menu-toggle,
.drawer-close,
button,
select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  font: inherit;
  color: var(--textPrimary);
  background: transparent;
  border: 1px solid var(--buttonBorderColor);
  border-radius: 8px;
  padding: 10px 14px;
  line-height: 1.2;
  height: 48px;
}

.menu-toggle,
button,
select { cursor: pointer; }

button:focus-visible,
select:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.15);
}

.menu-toggle {
  min-width: 160px;
  text-align: center;
}

.settings-drawer {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--drawerWidth);
  background: color-mix(in srgb, var(--bgColor) 92%, black 8%);
  border-right: 1px solid var(--buttonBorderColor);
  padding: 14px;
  z-index: 1000;
  transform: translateX(-110%);
  transition: transform 0.2s ease;
  overflow-x: hidden;
}


.settings-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.drawer-close {
  width: 48px;
  padding: 0;
}

.control-group {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.control-group > * {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

select {
  padding-right: 34px;
  background-color: color-mix(in srgb, var(--bgColor) 90%, black 10%);
  color: var(--textPrimary);
  padding-inline-end: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23cfd8dc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px 12px;
}

select option {
  background-color: var(--bgColor);
  color: var(--textPrimary);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 990;
}

#game {
  position: relative;
  text-align: left;
  border: 1px solid transparent;
  padding: 14px 20px;
  border-radius: 10px;
  white-space: pre;
  overflow: hidden;
  height: min(82vh, 900px);
}

#words {
  color: var(--textSecondary);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.line {
  display: block;
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
  line-height: 1.35;
  min-height: 1.35em;
}

.letter {
  position: relative;
  display: inline;
}

.letter.correct { color: var(--textPrimary); }
.letter.incorrect { color: var(--errorColor); }
.line-break-marker { opacity: 0.55; margin-left: 0.25ch; }
.line-break-marker.caret { opacity: 1; }

.letter.caret::after,
.letter.caret-right::after {
  content: "";
  position: absolute;
  bottom: -2px;
  width: 2px;
  height: 1em;
  background: var(--textPrimary);
  animation: blink 1s steps(1) infinite;
}

.letter.caret::after { left: 0; }
.letter.caret-right::after { left: 100%; }

@keyframes blink { 50% { opacity: 0; } }

#textModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1200;
  justify-content: center;
  align-items: center;
}

#modalContent {
  background: var(--bgColor);
  border: 1px solid var(--buttonBorderColor);
  border-radius: 10px;
  width: min(92vw, 560px);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#textInput {
  width: 100%;
  height: min(42dvh, 320px);
  padding: 10px;
  border: 1px solid var(--textSecondary);
  border-radius: 8px;
  font: inherit;
  color: var(--textPrimary);
  background: var(--bgColor);
  resize: none;
}

.action-buttons {
  display: flex;
  gap: 10px;
  justify-content: center;
}

#hiddenInput {
  position: absolute;
  top: -200px;
  opacity: 0;
  pointer-events: none;
}

[data-theme="dark-plus"]      { --bgColor:#1f2430; --textPrimary:#dfe6f3; --textSecondary:#9fb0c9; --buttonBorderColor:#a9bbd8; }
[data-theme="one-dark"]       { --bgColor:#282c34; --textPrimary:#d7dae0; --textSecondary:#9da5b4; --buttonBorderColor:#c5cad3; }
[data-theme="nord"]           { --bgColor:#2e3440; --textPrimary:#e5e9f0; --textSecondary:#81a1c1; --buttonBorderColor:#e5e9f0; }
[data-theme="dracula"]        { --bgColor:#282a36; --textPrimary:#f8f8f2; --textSecondary:#bd93f9; --buttonBorderColor:#f8f8f2; }
[data-theme="gruvbox-dark"]   { --bgColor:#282828; --textPrimary:#ebdbb2; --textSecondary:#a89984; --buttonBorderColor:#d5c4a1; }
[data-theme="monokai"]        { --bgColor:#272822; --textPrimary:#f8f8f2; --textSecondary:#a6e22e; --buttonBorderColor:#f8f8f2; }
[data-theme="solarized-dark"] { --bgColor:#002b36; --textPrimary:#93a1a1; --textSecondary:#586e75; --buttonBorderColor:#93a1a1; }
[data-theme="solarized-light"]{ --bgColor:#fdf6e3; --textPrimary:#657b83; --textSecondary:#93a1a1; --buttonBorderColor:#657b83; }
[data-theme="light-plus"]     { --bgColor:#ffffff; --textPrimary:#111111; --textSecondary:#5c6370; --buttonBorderColor:#111111; }
[data-theme="high-contrast"]  { --bgColor:#000000; --textPrimary:#ffffff; --textSecondary:#ffd700; --buttonBorderColor:#ffffff; --errorColor:#ff2d2d; }
[data-theme="terminal"]       { --bgColor:#001100; --textPrimary:#c6ffc6; --textSecondary:#6fcf6f; --buttonBorderColor:#8eff8e; }
[data-theme="tokyo-night"]    { --bgColor:#1a1b26; --textPrimary:#c0caf5; --textSecondary:#7aa2f7; --buttonBorderColor:#9aa5ce; }
[data-theme="catppuccin"]     { --bgColor:#1e1e2e; --textPrimary:#cdd6f4; --textSecondary:#89b4fa; --buttonBorderColor:#b4befe; }
[data-theme="everforest"]     { --bgColor:#2b3339; --textPrimary:#d3c6aa; --textSecondary:#a7c080; --buttonBorderColor:#83c092; }

@media (max-width: 768px) {
  main { width: calc(100% - 12px); margin: 8px auto; }
  #game { height: clamp(420px, calc(100dvh - 90px), 900px); padding: 10px 12px; }
  .menu-toggle { min-width: 130px; }
}
