:root {
  --bg: #F3F4F6;
  --text-primary: #3E3A36;
  --text-muted: #6F8895;
  --accent: #C26D52;
  --accent-secondary: #6F8895;
  --surface: #FAFAF8;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: Georgia, "Times New Roman", serif;
}

main {
  max-width: 520px;
  width: 100%;
  padding: 2rem 1.5rem 3rem;
}

.top-nav {
  margin-bottom: 0.75rem;
}

.back-btn {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
}

.back-btn:hover {
  color: var(--accent);
}

.game-title {
  font-size: 2.25rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-align: center;
  margin-bottom: 0.5rem;
}

.rules-btn {
  display: block;
  margin-bottom: 1rem;
  padding: 0.25rem 0.5rem;
  font-family: inherit;
  font-size: 0.85rem;
  background: transparent;
  border: 1px solid rgba(111, 136, 149, 0.5);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.rules-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.theme {
  text-align: center;
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
}

/* Scale */
.scale-block {
  margin-bottom: 0.75rem;
}

.weight-counter {
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 1rem 0;
}

.scale {
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 140px;
  padding: 0 1rem;
}

.scale::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  margin-left: -12px;
  width: 0;
  height: 0;
  border-left: 12px solid transparent;
  border-right: 12px solid transparent;
  border-bottom: 24px solid var(--text-primary);
  z-index: 0;
}

.scale-rotating {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0;
  position: relative;
  z-index: 1;
  margin-bottom: 24px;
  transform-origin: center 100%;
  transition: transform 0.35s ease;
}

.scale-bar {
  width: 140px;
  height: 5px;
  margin-bottom: 0;
  background: var(--text-primary);
  border-radius: 2px;
  flex-shrink: 0;
}

.scale-pan {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  width: 90px;
  min-height: 50px;
  padding: 0.5rem;
}

.scale-pan--target {
  align-items: center;
}

.scale-pan--words {
  align-items: center;
}

.scale-weight {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--accent);
}

.words-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-content: flex-end;
  gap: 0.25rem 0.35rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}

.words-list .words-empty {
  color: var(--text-muted);
  font-style: normal;
}

.words-list .word-chip {
  position: relative;
  display: inline-block;
  padding: 0.2rem 0.45rem;
  padding-right: 1.35rem;
  background: rgba(194, 109, 82, 0.14);
  border-radius: 4px;
  color: var(--text-primary);
  white-space: nowrap;
}

.words-list .word-chip-label em {
  font-style: normal;
  color: var(--text-muted);
  font-size: 0.9em;
}

.words-list .chip-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 1.1rem;
  height: 1.1rem;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: rgba(62, 58, 54, 0.2);
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.words-list .word-chip:hover .chip-remove,
.words-list .chip-remove:focus {
  opacity: 1;
}

.words-list .chip-remove:hover {
  background: rgba(194, 109, 82, 0.3);
}

/* Input block: button, counter, word – centered above keyboard */
.input-block {
  text-align: center;
  margin-bottom: 1rem;
}

.input-block-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.input-block-row:last-child {
  margin-bottom: 0;
}

.input-block-row--word {
  min-height: 1.5em;
}

.word-display {
  min-height: 1.5em;
  min-width: 80px;
  font-size: 1.25rem;
  letter-spacing: 0.05em;
  color: var(--text-primary);
}

.word-weight-display {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.submit-btn {
  padding: 0.35rem 0.75rem;
  font-family: inherit;
  font-size: 0.9rem;
  background: var(--surface);
  border: 1px solid rgba(111, 136, 149, 0.5);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.submit-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.submit-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.error-message {
  min-height: 1.5em;
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 1rem;
  text-align: center;
}

.win-message {
  text-align: center;
  font-size: 1.1rem;
  color: var(--accent);
  margin-bottom: 1rem;
}

/* Typewriter keyboard */
.keyboard-frame {
  margin-top: 1.5rem;
  padding: 1rem;
  background: linear-gradient(180deg, #4a4a4a 0%, #3d3d3d 100%);
  border-radius: 8px;
  border: 2px solid #2d2d2d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 4px 12px rgba(0, 0, 0, 0.2);
}

.keyboard {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.keyboard-row {
  display: flex;
  gap: 4px;
  justify-content: center;
}

.keyboard-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 32px;
  padding: 2px 4px;
  font-family: "Courier New", Courier, monospace;
  font-size: 0.75rem;
  font-weight: 600;
  color: #e2e0dc;
  background: linear-gradient(180deg, #5c5c5c 0%, #454545 50%, #3a3a3a 100%);
  border: 1px solid #2d2d2d;
  border-radius: 3px;
  box-shadow: 0 2px 0 #2d2d2d, inset 0 1px 0 rgba(255, 255, 255, 0.08);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.keyboard-key .key-letter {
  font-size: 0.8rem;
  line-height: 1.1;
  color: inherit;
}

.keyboard-key .key-value {
  font-size: 0.6rem;
  color: rgba(226, 224, 220, 0.85);
  line-height: 1;
}

.keyboard-key:hover {
  background: linear-gradient(180deg, #6a6a6a 0%, #525252 50%, #454545 100%);
  color: var(--accent);
}

.keyboard-key:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 #2d2d2d, inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.keyboard-key.key-backspace {
  min-width: 44px;
  font-size: 0.7rem;
}

/* Rules dialog */
.rules-dialog {
  margin: 0;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 360px;
  padding: 1.25rem;
  border: 1px solid var(--text-primary);
  background: var(--bg);
  color: var(--text-primary);
  font-family: inherit;
  border-radius: 8px;
}

.rules-dialog::backdrop {
  background: rgba(62, 58, 54, 0.4);
}

.rules-dialog h2 {
  font-size: 1.25rem;
  color: var(--accent);
  margin-bottom: 0.75rem;
}

.rules-list {
  margin: 0 0 1rem 1.25rem;
  padding: 0;
}

.rules-list li {
  margin-bottom: 0.35rem;
}

.dialog-close {
  padding: 0.25rem 0.5rem;
  font-family: inherit;
  font-size: 0.8rem;
  background: var(--surface);
  border: 1px solid rgba(111, 136, 149, 0.5);
  border-radius: 6px;
  color: var(--text-primary);
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.dialog-close:hover {
  color: var(--accent);
  border-color: var(--accent);
}