/* Homophone Fun — styles. Theme via CSS variables (see :root / html.dark). */

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

:root {
  --bg: #f5ecd9;
  --fg: #222;
  --card-bg: #fdfaf3;
  --card-border: #888;
  --input-bg: #efe6d0;
  --input-fg: #222;
  --input-border: #888;
  --input-placeholder: #999;
  --btn-bg: #fff;
  --btn-fg: #222;
  --btn-border: #444;
  --icon-btn-bg: #fff;
  --icon-btn-fg: #444;
  --icon-btn-border: #888;
  --modal-bg: #fff;
  --modal-fg: #222;
  --modal-muted: #444;
  --sample-bg: #fafafa;
  --feedback-fg: #555;
  --correct: #2a7a2a;
  --correct-bg: #f0fff0;
  --sample-input-bg: #f0fff0;
  --sample-input-fg: #2a7a2a;
  --on-blue: #e8e8e8;
  --close-color: #888;
  --kbd-bg: #f0f0f0;
  --kbd-border: #ccc;
  --shadow: 0 4px 16px rgba(60, 60, 60, 0.2);
  --title-shadow: 2px 2px 3px rgba(30, 58, 138, 0.6);
  --btn-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  --input-inset: inset 0 2px 4px rgba(0, 0, 0, 0.18);
}

html.dark {
  --bg: #2b2b2b;
  --fg: #e0e0e0;
  --card-bg: #383838;
  --card-border: #555;
  --input-bg: #303030;
  --input-fg: #e0e0e0;
  --input-border: #666;
  --input-placeholder: #888;
  --btn-bg: #404040;
  --btn-fg: #e0e0e0;
  --btn-border: #666;
  --icon-btn-bg: #404040;
  --icon-btn-fg: #e0e0e0;
  --icon-btn-border: #666;
  --modal-bg: #383838;
  --modal-fg: #e0e0e0;
  --modal-muted: #bbb;
  --sample-bg: #424242;
  --feedback-fg: #aaa;
  --correct: #6abf6a;
  --correct-bg: #1f3a1f;
  --sample-input-bg: #1f3a1f;
  --sample-input-fg: #6abf6a;
  --close-color: #aaa;
  --kbd-bg: #333;
  --kbd-border: #555;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  --btn-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
  --input-inset: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

body {
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--fg);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.game {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 0.85rem 1rem;
}

@media (min-width: 480px) {
  .game {
    padding: 2rem 0 1rem;
  }
}

/* Touch-only devices: drop hover backgrounds (avoid "sticky" hover on tap). */
@media (hover: none) {
  .game__icon-btn:hover,
  #hint-btn:hover,
  #skip-btn:hover,
  #solve-btn:hover,
  .game__button:hover {
    background: var(--icon-btn-bg);
    color: var(--icon-btn-fg);
    border-color: var(--icon-btn-border);
  }
}

.game__header {
  width: 100%;
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.game__header-row {
  width: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
}

.game__header-row--top {
  padding: max(0.45rem, env(safe-area-inset-top)) 0.75rem 0.35rem;
  padding-right: max(0.75rem, env(safe-area-inset-right));
  padding-left: max(0.75rem, env(safe-area-inset-left));
  justify-content: space-between;
  gap: 0.5rem;
}

.game__header-row--title {
  padding: 0 0.75rem 0.6rem;
  justify-content: center;
}

.game__header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.game__app-btn {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  padding: 0.3rem 0.65rem;
  min-height: 2.75rem;
  border: 1px solid var(--btn-border);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  cursor: default;
  white-space: nowrap;
  opacity: 0.85;
  -webkit-touch-callout: none;
  user-select: none;
}

.game__title {
  font-family: 'Roboto', sans-serif;
  font-weight: 900;
  font-size: 1.85rem;
  letter-spacing: 0.05em;
  white-space: nowrap;
  text-align: center;
  color: #87CEEB;
  text-shadow: var(--title-shadow);
}

.game__icon-btn {
  flex-shrink: 0;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 6px;
  background: var(--icon-btn-bg);
  border: 1.5px solid var(--icon-btn-border);
  box-shadow: var(--btn-shadow);
  font-size: 1.25rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--icon-btn-fg);
  line-height: 1;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-touch-callout: none;
  user-select: none;
}

.game__icon-btn:hover {
  background: #4a90e2;
  color: var(--on-blue);
  border-color: #4a90e2;
}

.game__card {
  width: 100%;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 10px;
  padding: 3.5rem 1.5rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin: auto 0;
}

@media (max-width: 479px) {
  .game__card {
    padding: 2rem 0.85rem;
    gap: 1rem;
    max-width: 86%;
  }
}

/* Landscape phones (limited vertical height). */
@media (orientation: landscape) and (max-height: 500px) {
  .game {
    padding: 0.5rem 0.5rem 0.75rem;
  }
  .game__card {
    padding: 0.85rem 1rem;
    gap: 0.6rem;
    max-width: 640px;
  }
  .game__title {
    font-size: 1.4rem;
  }
  .game__form {
    gap: 1rem;
  }
  .game__statement {
    min-height: 1.5rem;
    font-size: 1.05rem;
  }
  .game__feedback {
    min-height: 1.5rem;
  }
}

.game__statement {
  font-size: 1.25rem;
  min-height: 3rem;
  line-height: 1.4;
  text-align: center;
  color: var(--fg);
}
.game__statement::first-letter {
  text-transform: uppercase;
}

.game__form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.5rem;
}

.game__inputs {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.game__input {
  font-family: Arial, Helvetica, sans-serif;
  text-transform: uppercase;
  font-weight: bold;
  font-size: 1.25rem;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--input-border);
  border-radius: 10px;
  background: var(--input-bg);
  box-shadow: var(--input-inset);
  color: var(--input-fg);
  width: 11rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
}

@media (max-width: 479px) {
  .game__input {
    width: 8.5rem;
    font-size: 1.1rem;
    padding: 0.55rem 0.5rem;
  }
}

/* Prevent iOS Safari auto-zoom on input focus: ensure font-size >= 16px on focus. */
.game__input:focus {
  font-size: 1.25rem;
}
.game__input::placeholder {
  color: var(--input-placeholder);
  text-transform: none;
  font-weight: normal;
}

.game__input:focus {
  outline: 2px solid #4a90e2;
  outline-offset: 2px;
}

.game__input:disabled {
  cursor: not-allowed;
}

.game__input--correct {
  color: var(--correct);
  border-color: var(--correct);
  background: var(--correct-bg);
  box-shadow: none;
}

.game__feedback {
  font-size: 1rem;
  min-height: 2.75rem;
  color: var(--feedback-fg);
  font-weight: bold;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.game__feedback--correct {
  color: var(--correct);
  font-size: 2rem;
  animation: pop 0.4s ease-out;
}

.game__feedback--almost {
  color: #1e90ff;
}

.game__feedback--wrong {
  color: #e67e22;
}

@keyframes pop {
  0%   { transform: scale(0.5); opacity: 0; }
  50%  { transform: scale(1.2); }
  100% { transform: scale(1);   opacity: 1; }
}

.game__buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.game__button {
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  font-size: 1rem;
  padding: 0.55rem 1.4rem;
  min-height: 2.75rem;
  min-width: 5rem;
  border: 1px solid var(--btn-border);
  border-radius: 4px;
  background: var(--btn-bg);
  box-shadow: var(--btn-shadow);
  color: var(--btn-fg);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  -webkit-touch-callout: none;
  user-select: none;
}

#hint-btn:hover,
#skip-btn:hover,
#solve-btn:hover {
  background: #4a90e2;
  color: var(--on-blue);
  border-color: #4a90e2;
}

.game__button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.game__button--primary {
  background: #4a90e2;
  color: var(--on-blue);
  border-color: #4a90e2;
  min-width: 8rem;
  justify-content: center;
}

.game__button--primary:hover {
  background: #357abd;
  border-color: #357abd;
}

.game__button--primary:disabled {
  background: #ccc;
  border-color: #ccc;
  color: #666;
}

/* Confetti overlay */
.confetti {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* Help/rules modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none;
}

.modal__backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.modal__card {
  position: relative;
  background: var(--modal-bg);
  color: var(--modal-fg);
  border-radius: 14px;
  padding: 1.75rem 1.5rem 1.5rem;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  text-align: left;
  text-transform: none;
  font-weight: normal;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.modal__card h2 {
  font-size: 1.4rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  color: var(--modal-fg);
}

.modal__card h3 {
  font-size: 0.95rem;
  font-weight: bold;
  letter-spacing: 0.05em;
  margin-top: 0.25rem;
  color: var(--modal-muted);
}

.modal__card p {
  line-height: 1.5;
  font-size: 0.95rem;
}

.modal__card kbd {
  background: var(--kbd-bg);
  border: 1px solid var(--kbd-border);
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.85em;
  font-family: monospace;
  text-transform: none;
}

.modal__close {
  position: absolute;
  top: 0.4rem;
  right: 0.4rem;
  width: 2.75rem;
  height: 2.75rem;
  border: none;
  background: transparent;
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  color: var(--close-color);
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal__close:hover {
  color: var(--fg);
}

/* Sample puzzle (inside modal) */
.modal__sample {
  background: var(--sample-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.sample__clue {
  font-size: 1rem;
  text-align: center;
  color: var(--modal-fg);
}
.sample__clue::first-letter {
  text-transform: uppercase;
}

.sample__form {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.sample__input {
  font-family: Arial, Helvetica, sans-serif;
  text-transform: uppercase;
  font-weight: bold;
  font-size: 1.25rem;
  padding: 0.6rem 0.75rem;
  border: 1.5px solid var(--sample-input-fg);
  border-radius: 10px;
  background: var(--sample-input-bg);
  color: var(--sample-input-fg);
  width: 7rem;
  text-align: center;
}

.sample__note {
  font-size: 0.85rem;
  color: var(--modal-muted);
  text-transform: none;
  text-align: center;
  font-weight: normal;
  font-style: italic;
}
