/* style.css — CloserWords styles */

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f5f5f5;
  --text: #1a1a1a;
  --grid-bg: #ffffff;
  --grid-border: #ddd;
  --highlight-row: #bbdefb;
  --highlight-cell: #1565c0;
  --highlight-cell-text: #ffffff;
  --selected-row: #e3f2fd;
  --btn-bg: #1565c0;
  --btn-text: #ffffff;
  --btn-secondary-bg: #e0e0e0;
  --btn-secondary-text: #333;
  --composed-bg: #ffffff;
  --composed-border: #1565c0;
}

body.dark-mode {
  --bg: #121212;
  --text: #e0e0e0;
  --grid-bg: #1e1e1e;
  --grid-border: #333;
  --highlight-row: #1a3a5c;
  --highlight-cell: #42a5f5;
  --highlight-cell-text: #000000;
  --selected-row: #1a2a3a;
  --btn-bg: #42a5f5;
  --btn-text: #000;
  --btn-secondary-bg: #333;
  --btn-secondary-text: #e0e0e0;
  --composed-bg: #1e1e1e;
  --composed-border: #42a5f5;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

/* --- App Layout --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 8px;
  gap: 8px;
}

/* --- Top Bar --- */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  flex-shrink: 0;
}

.app-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.controls {
  display: flex;
  gap: 8px;
}

.controls button {
  padding: 6px 14px;
  border: 2px solid var(--btn-bg);
  border-radius: 8px;
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
}

/* --- Composed Text --- */
.message-display {
  flex-shrink: 0;
  background: var(--composed-bg);
  border: 3px solid var(--composed-border);
  border-radius: 12px;
  padding: 12px 16px;
  min-height: 60px;
}

.composed-text {
  font-size: 1.6rem;
  font-weight: 600;
  word-wrap: break-word;
  line-height: 1.4;
}

/* --- Letter Grid --- */
.letter-grid-container {
  flex: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
  position: relative;
}

.letter-grid {
  display: grid;
  gap: 4px;
  width: 100%;
  height: 100%;
}

.grid-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grid-bg);
  border: 2px solid var(--grid-border);
  border-radius: 8px;
  font-size: clamp(1.5rem, 5vmin, 3.5rem);
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}

.grid-cell:active {
  opacity: 0.7;
}

.grid-cell.highlighted-row {
  background: var(--highlight-row);
  border-color: var(--highlight-cell);
}

.grid-cell.selected-row {
  background: var(--selected-row);
}

.grid-cell.highlighted-cell {
  background: var(--highlight-cell);
  color: var(--highlight-cell-text);
  transform: scale(1.05);
  border-color: var(--highlight-cell);
}

/* --- Action Buttons --- */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 0.5fr 0.5fr;
  gap: 8px;
  flex-shrink: 0;
  padding: 4px 0;
}

.btn-action {
  padding: 16px 8px;
  border: none;
  border-radius: 12px;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 56px;
  transition: opacity 0.15s;
}

.btn-action:active {
  opacity: 0.7;
}

.btn-next {
  background: var(--btn-bg);
  color: var(--btn-text);
}

.btn-select {
  background: #2e7d32;
  color: #fff;
}

.btn-backspace {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
  font-size: 1.4rem;
}

.btn-clear {
  background: #c62828;
  color: #fff;
}

/* --- RTL adjustments --- */
[dir="rtl"] .letter-grid {
  direction: rtl;
}

[dir="rtl"] .composed-text {
  direction: rtl;
  text-align: right;
}

/* --- Needs Mode --- */
.needs-mode .grid-cell {
  flex-direction: column;
  gap: 4px;
  font-size: clamp(0.9rem, 3vmin, 1.6rem);
  font-weight: 600;
}

.needs-mode .grid-cell .need-emoji {
  font-size: clamp(1.8rem, 6vmin, 3.5rem);
  line-height: 1;
}

.needs-mode .grid-cell .need-label {
  line-height: 1.1;
}

/* --- Needs Overlay --- */
.needs-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 12px;
  z-index: 10;
  cursor: pointer;
  gap: 12px;
}

.needs-overlay.hidden {
  display: none;
}

.needs-overlay-emoji {
  font-size: clamp(4rem, 15vmin, 8rem);
  line-height: 1;
}

.needs-overlay-label {
  font-size: clamp(1.8rem, 6vmin, 3.5rem);
  font-weight: 700;
  text-align: center;
}

/* When in needs mode, action buttons show only Next + Select */
.action-buttons.needs-layout {
  grid-template-columns: 1fr 1fr;
}

/* --- Responsive --- */
@media (max-width: 480px) {
  .app-title {
    font-size: 1rem;
  }

  .composed-text {
    font-size: 1.3rem;
  }

  .grid-cell {
    border-radius: 6px;
  }

  .btn-action {
    font-size: 1rem;
    padding: 12px 6px;
    min-height: 48px;
  }
}
