/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0;
  background: #fdf6e8;
  font-family: system-ui, sans-serif;
  color: #3d2b1a;
}

.game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 16px 32px;
}

.game-title {
  margin: 0 0 6px;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: lowercase;
  color: #3d2b1a;
}

.game-stats {
  margin: 14px 0 0;
  font-family: monospace;
  font-size: 0.78rem;
  color: #a07850;
  letter-spacing: 0.05em;
  min-height: 1.2em;
}

.game-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.game-dpad {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.game-dpad-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.game-dpad-btn {
  width: 44px;
  height: 44px;
  background: #f5ead8;
  border: 1.5px solid #d4b896;
  border-radius: 8px;
  color: #3d2b1a;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  padding: 0;
}

.game-dpad-btn:active {
  background: #eddec4;
  transform: scale(0.92);
}


.game-canvas-wrapper {
  position: relative;
  line-height: 0;
}

.game-panel {
  width: 160px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fdf6e8;
  border: 1px solid #d4b896;
  border-radius: 8px;
  box-shadow: 0 2px 16px rgba(100, 60, 20, 0.12);
}

.game-panel-tabs {
  display: flex;
  flex-shrink: 0;
  border-bottom: 1px solid #e8d9c0;
}

.game-panel-tab {
  flex: 1;
  padding: 7px 4px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-size: 0.9rem;
  color: #c4a882;
  transition: color 0.1s;
  position: relative;
}

.game-panel-tab:hover { color: #a07850; }

.game-panel[data-active-tab="chat"] .game-panel-tab[data-tab="chat"],
.game-panel[data-active-tab="inventory"] .game-panel-tab[data-tab="inventory"] {
  color: #3d2b1a;
  border-bottom-color: #a07850;
}

.game-panel-tab.has-unread::after {
  content: '';
  position: absolute;
  top: 5px;
  right: calc(50% - 10px);
  width: 5px;
  height: 5px;
  background: #a07850;
  border-radius: 50%;
}

.game-panel-pane { display: none; flex: 1; overflow: hidden; }

.game-panel[data-active-tab="chat"] .game-panel-pane[data-pane="chat"],
.game-panel[data-active-tab="inventory"] .game-panel-pane[data-pane="inventory"] {
  display: flex;
}

.game-history {
  flex-direction: column-reverse;
  gap: 8px;
  padding: 10px;
}

.game-inventory {
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  overflow-y: auto;
}

.inventory-empty {
  font-family: monospace;
  font-size: 0.65rem;
  color: #e0cdb0;
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.7;
  margin: auto;
  opacity: 0.7;
}

.inventory-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: monospace;
  font-size: 0.72rem;
  color: #5a3f28;
  flex-shrink: 0;
}


.game-history-msg {
  font-family: monospace;
  font-size: 0.7rem;
  line-height: 1.5;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: #a07850;
  flex-shrink: 0;
}

.game-history-msg--self {
  color: #5a3f28;
  text-align: right;
  padding-left: 12px;
}

.game-history-placeholder {
  font-family: monospace;
  font-size: 0.65rem;
  color: #e0cdb0;
  letter-spacing: 0.06em;
  text-align: center;
  line-height: 1.7;
  margin: auto;
  flex-shrink: 0;
  opacity: 0.7;
}

@media (prefers-reduced-motion: no-preference) {
  .game-history-msg {
    animation: msg-fade 0.15s ease-out;
  }
}

@keyframes msg-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.game-canvas {
  display: block;
  border: 1px solid #d4b896;
  border-radius: 8px;
  outline: none;
  box-shadow: 0 2px 16px rgba(100, 60, 20, 0.12);
}

.game-canvas:focus {
  outline: 2px solid #a07850;
  outline-offset: 3px;
}

.action-panel {
  position: absolute;
  left: var(--cell-center-x);
  bottom: calc(100% - var(--cell-top-y) + 4px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #fdf6e8;
  border: 2px solid #3d2b1a;
  border-radius: 5px;
  padding: 6px 10px;
  white-space: nowrap;
  z-index: 10;
  /* Entry animation: scale up from the tail tip */
  transform: translateX(-50%) scale(0.88);
  transform-origin: 50% calc(100% + 10px);
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.12s ease-out, transform 0.12s ease-out, visibility 0s 0.12s;
}

.action-panel::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid #3d2b1a;
}

.action-panel::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 10px;
  background: #fdf6e8;
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  z-index: 1;
}

.action-panel.active {
  visibility: visible;
  opacity: 1;
  transform: translateX(-50%) scale(1);
  transition: opacity 0.12s ease-out, transform 0.12s ease-out, visibility 0s 0s;
}

@media (prefers-reduced-motion: reduce) {
  .action-panel { transition: none; }
}

.action-panel-type {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #b89a70;
  text-transform: uppercase;
  padding-bottom: 5px;
  margin-bottom: 1px;
  border-bottom: 1px solid #e8d9c0;
}

.action-panel-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  color: #3d2b1a;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 5px 0;
  text-align: left;
  text-transform: capitalize;
  display: flex;
  align-items: center;
}

.action-panel-btn:hover {
  color: #7a4f2a;
}

.action-panel-btn:active {
  transform: translateY(1px);
}

.action-panel-btn:focus-visible {
  outline: 2px solid #a07850;
  outline-offset: 2px;
  border-radius: 2px;
}

.chat-input-wrapper {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  visibility: hidden;
  background: #fdf6e8;
  border: 2px solid #3d2b1a;
  border-radius: 5px;
  padding: 8px 12px;
  white-space: nowrap;
}

.chat-input-wrapper::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-top: 8px solid #3d2b1a;
}

.chat-input-wrapper::before {
  content: '';
  position: absolute;
  bottom: -8px;
  left: 50%;
  transform: translateX(-50%);
  width: 12px;
  height: 10px;
  background: #fdf6e8;
  clip-path: polygon(0% 0%, 100% 0%, 50% 100%);
  z-index: 1;
}

.chat-input-wrapper.active {
  visibility: visible;
}

.chat-input {
  font-family: 'Press Start 2P', monospace;
  font-size: 9px;
  padding: 0;
  min-width: 60px;
  border: none;
  background: transparent;
  color: #3d2b1a;
  outline: none;
  display: block;
}

.chat-input::placeholder {
  color: #b89a70;
}

/* Login */

.login-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 80px 16px 32px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(320px, 100%);
  margin-top: 8px;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field label {
  font-size: 0.72rem;
  font-family: monospace;
  letter-spacing: 0.06em;
  color: #a07850;
  text-transform: lowercase;
}

.login-field input {
  font-size: 0.9rem;
  font-family: system-ui, sans-serif;
  padding: 10px 12px;
  border: 1.5px solid #d4b896;
  border-radius: 6px;
  background: #fff9f0;
  color: #3d2b1a;
  outline: none;
  transition: border-color 0.15s;
}

.login-field input:focus {
  border-color: #a07850;
}

.login-field input::placeholder {
  color: #c4a882;
}

.login-form input[type="submit"] {
  margin-top: 4px;
  padding: 11px;
  font-size: 0.8rem;
  font-family: monospace;
  letter-spacing: 0.08em;
  text-transform: lowercase;
  background: #3d2b1a;
  color: #fdf6e8;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.login-form input[type="submit"]:hover {
  background: #5a3f28;
}

.login-form input[type="submit"]:focus-visible {
  outline: 2px solid #a07850;
  outline-offset: 2px;
}

.login-error {
  font-size: 0.78rem;
  font-family: monospace;
  color: #b84040;
  margin: 8px 0 0;
  letter-spacing: 0.04em;
}

/* Email badge (step 2) */

.login-email-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  padding: 9px 14px;
  background: #f5ead8;
  border: 1.5px solid #d4b896;
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: system-ui, sans-serif;
  color: #3d2b1a;
  width: min(320px, 100%);
}

.login-change {
  margin-left: auto;
  font-size: 0.72rem;
  font-family: monospace;
  color: #a07850;
  text-decoration: none;
  letter-spacing: 0.04em;
}

.login-change:hover {
  color: #3d2b1a;
}

/* Sprite picker */

.sprite-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.sprite-option {
  display: none;
}

.sprite-option + label {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  border: 1.5px solid #d4b896;
  border-radius: 6px;
  cursor: pointer;
  background: #fff9f0;
  transition: border-color 0.1s, background 0.1s;
  user-select: none;
}

.sprite-option:checked + label {
  border-color: #a07850;
  background: #f5ead8;
  box-shadow: 0 0 0 2px #a0785033;
}

.sprite-option + label:hover {
  border-color: #a07850;
}

/* Sign out */

.signout-btn {
  margin-top: 14px;
  background: none;
  border: none;
  font-size: 0.72rem;
  font-family: monospace;
  color: #c4a882;
  cursor: pointer;
  letter-spacing: 0.05em;
  text-transform: lowercase;
  padding: 0;
}

.signout-btn:hover {
  color: #a07850;
}

.signout-btn:focus-visible {
  outline: 2px solid #a07850;
  outline-offset: 2px;
  border-radius: 2px;
}
