/* ===========================
   Okey 101 Masasi - Kahvehane Theme
   =========================== */

:root {
  --green-felt: #1a472a;
  --green-felt-dark: #0f2e1a;
  --green-felt-light: #2d6b3f;
  --wood-brown: #6B3410;
  --wood-dark: #4a2409;
  --wood-light: #D2A679;
  --wood-lighter: #e8caa8;
  --cream: #FFF8E7;
  --cream-dark: #f0e6cc;
  --gold: #C5A55A;
  --gold-light: #dcc47a;
  --text-dark: #2c1810;
  --text-light: #FFF8E7;
  --text-muted: #8a7560;
  --shadow: rgba(44, 24, 16, 0.2);
  --shadow-strong: rgba(44, 24, 16, 0.35);
}

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

html, body {
  overflow-x: hidden;
  min-height: 100%;
  width: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background-color: var(--cream);
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 50px,
      rgba(210, 166, 121, 0.05) 50px,
      rgba(210, 166, 121, 0.05) 51px
    );
  color: var(--text-dark);
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
  font-weight: 700;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0;
  min-height: 100vh;
}

/* ===========================
   Return Banner
   =========================== */

.return-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--gold), var(--gold-light));
  color: var(--wood-dark);
  padding: 12px 16px;
  border-radius: 10px;
  margin-top: 16px;
  border: 2px solid var(--wood-light);
  box-shadow: 0 2px 8px var(--shadow);
}

.return-banner a {
  color: var(--wood-dark);
  text-decoration: none;
  font-weight: 600;
  font-size: 1rem;
}

.return-banner a:hover {
  text-decoration: underline;
}

.banner-close {
  background: none;
  border: none;
  color: var(--wood-brown);
  font-size: 1.25rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  opacity: 0.7;
}

.banner-close:hover {
  opacity: 1;
}

/* ===========================
   Home Page
   =========================== */

.home-page {
  padding: 0 16px;
}

.home-header {
  text-align: center;
  padding: 40px 0 24px;
}

.home-header h1 {
  color: var(--green-felt);
  font-size: 2rem;
  margin-bottom: 8px;
}

.slogan {
  color: var(--text-muted);
  font-size: 1rem;
  font-style: italic;
}

.home-info {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.home-info-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: white;
  border-radius: 10px;
  border: 1.5px solid var(--cream-dark);
}

.home-info-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.home-info-item p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ===========================
   Form Styles
   =========================== */

.create-form {
  background: white;
  padding: 28px 24px;
  border-radius: 16px;
  border: 2px solid var(--wood-light);
  box-shadow: 0 4px 16px var(--shadow);
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-weight: 600;
  color: var(--wood-brown);
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.form-group input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--cream-dark);
  border-radius: 10px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--text-dark);
  background: var(--cream);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 48px;
}

.form-group input:focus {
  outline: none;
  border-color: var(--green-felt-light);
  box-shadow: 0 0 0 3px rgba(45, 107, 63, 0.15);
}

.form-group input::placeholder {
  color: var(--text-muted);
  opacity: 0.7;
}

/* ===========================
   Buttons
   =========================== */

.btn-create {
  display: block;
  width: 100%;
  padding: 16px 24px;
  background: linear-gradient(180deg, var(--green-felt-light), var(--green-felt));
  color: var(--text-light);
  border: 2px solid var(--green-felt-dark);
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 600;
  font-family: 'Playfair Display', Georgia, serif;
  cursor: pointer;
  min-height: 52px;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 3px 8px var(--shadow);
  text-align: center;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.btn-create:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--green-felt), var(--green-felt-dark));
  box-shadow: 0 4px 12px var(--shadow-strong);
  transform: translateY(-1px);
}

.btn-create:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 4px var(--shadow);
}

.btn-create:disabled {
  background: var(--cream-dark);
  color: var(--text-muted);
  border-color: var(--cream-dark);
  cursor: not-allowed;
  box-shadow: none;
}

/* ===========================
   Table View
   =========================== */

.table-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
}

.table-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 16px 32px;
  width: 100%;
  flex: 1;
}

.table-header {
  text-align: center;
  padding: 0 0 16px;
}

.table-header h1 {
  color: var(--green-felt);
  font-size: 1.6rem;
}

/* 4-Seat Layout Grid */
.table-layout {
  display: grid;
  grid-template-columns: 90px 1fr 90px;
  grid-template-rows: 90px 1fr 90px;
  grid-template-areas:
    ".     north  ."
    "west  center east"
    ".     south  .";
  gap: 12px;
  padding: 0;
  width: 100%;
  max-width: 420px;
}

.seat-slot {
  display: flex;
  justify-content: center;
  align-items: center;
}

.slot-north { grid-area: north; }
.slot-south { grid-area: south; }
.slot-west  { grid-area: west; }
.slot-east  { grid-area: east; }

/* Table Surface (Center) */
.table-surface {
  grid-area: center;
  background: linear-gradient(145deg, var(--green-felt-light), var(--green-felt));
  border: 4px solid var(--wood-brown);
  border-radius: 16px;
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1;
  box-shadow:
    inset 0 2px 8px rgba(0, 0, 0, 0.2),
    0 4px 16px var(--shadow-strong);
  position: relative;
}

/* Table glow when all 4 seats are filled */
.table-ready .table-surface {
  animation: tableGlow 1.5s ease-in-out infinite;
}

.table-surface::before {
  content: '';
  position: absolute;
  inset: 4px;
  border: 1px solid rgba(255, 248, 231, 0.15);
  border-radius: 12px;
  pointer-events: none;
}

.okey-decoration {
  font-size: 2rem;
  margin-bottom: 8px;
  opacity: 0.85;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.okey-tile {
  display: block;
}

.table-status {
  color: var(--text-light);
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.9;
  text-align: center;
  letter-spacing: 0.03em;
}

/* ===========================
   Seat Animations
   =========================== */

@keyframes seatAppear {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes seatPulse {
  0%, 100% {
    box-shadow: 0 3px 10px var(--shadow);
  }
  50% {
    box-shadow: 0 3px 18px var(--shadow-strong);
  }
}

@keyframes seatBounce {
  0%, 100% {
    transform: scale(1.08) translateY(0);
  }
  50% {
    transform: scale(1.08) translateY(-4px);
  }
}

@keyframes seatFadeOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.9);
  }
}

@keyframes tableGlow {
  0%, 100% {
    box-shadow:
      inset 0 2px 8px rgba(0, 0, 0, 0.2),
      0 4px 16px var(--shadow-strong);
  }
  50% {
    box-shadow:
      inset 0 2px 8px rgba(0, 0, 0, 0.2),
      0 4px 24px var(--shadow-strong),
      0 0 12px rgba(197, 165, 90, 0.3);
  }
}

/* ===========================
   Seat Cards
   =========================== */

.seat {
  border-radius: 12px;
  padding: 8px;
  text-align: center;
  width: 90px;
  height: 90px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  animation: seatAppear 0.4s ease-out both;
}

/* Staggered animation delays per position */
.slot-north .seat { animation-delay: 0.05s; }
.slot-west .seat  { animation-delay: 0.15s; }
.slot-east .seat  { animation-delay: 0.25s; }
.slot-south .seat { animation-delay: 0.35s; }

.seat-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  font-weight: 600;
}

/* Occupied Seat */
.seat-occupied {
  background: linear-gradient(145deg, var(--wood-lighter), var(--wood-light));
  border: 2px solid var(--wood-brown);
  box-shadow: 0 3px 10px var(--shadow);
  animation: seatAppear 0.4s ease-out both, seatPulse 2s ease-in-out 0.5s;
}

/* Kicked seat fade-out state */
.seat-just-kicked {
  animation: seatFadeOut 0.4s ease-in both;
}

.seat-occupied .seat-label {
  color: var(--wood-brown);
}

.seat-player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.host-badge {
  color: var(--gold);
  font-size: 0.9rem;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.2));
}

.player-name {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 0.9rem;
  word-break: break-word;
}

/* Empty Seat */
.seat-empty {
  border: 2px dashed var(--wood-light);
  background: rgba(210, 166, 121, 0.08);
}

.seat-empty .seat-label {
  color: var(--text-muted);
}

.seat-empty-text {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  opacity: 0.7;
}

/* ===========================
   Header Bar
   =========================== */

.header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  width: 100%;
  background: linear-gradient(180deg, var(--green-felt), var(--green-felt-dark));
  border-bottom: 3px solid var(--wood-brown);
  box-shadow: 0 2px 8px var(--shadow-strong);
}

.header-bar h1 {
  font-size: 1.1rem;
  color: var(--text-light);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seat-counter {
  font-weight: 400;
  color: var(--gold-light);
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.refresh-indicator {
  font-size: 0.65rem;
  color: var(--gold-light);
  opacity: 0.6;
  transition: opacity 0.3s;
  white-space: nowrap;
  font-family: 'Inter', sans-serif;
}

.refresh-indicator.pulse {
  opacity: 1;
}

.refresh-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: rgba(255, 248, 231, 0.1);
  border: 1.5px solid rgba(255, 248, 231, 0.25);
  border-radius: 8px;
  color: var(--text-light);
  font-size: 1.2rem;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  position: relative;
}

.refresh-btn:hover {
  background: rgba(255, 248, 231, 0.2);
  border-color: rgba(255, 248, 231, 0.4);
  color: white;
}

.refresh-btn::after {
  content: '';
  position: absolute;
  top: -2px;
  right: -2px;
  width: 8px;
  height: 8px;
  background: #2ecc71;
  border-radius: 50%;
  animation: dotPulse 2s ease-in-out infinite;
}

@keyframes dotPulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ===========================
   Tab Navigation
   =========================== */

.tab-nav {
  display: flex;
  gap: 0;
  background: var(--green-felt-dark);
  width: 100%;
}

.tab-nav a {
  flex: 1;
  padding: 10px 20px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: rgba(255, 248, 231, 0.5);
  border-bottom: 3px solid transparent;
  font-weight: 500;
  font-size: 0.9rem;
  transition: color 0.2s, border-color 0.2s;
}

.tab-nav a.active {
  color: var(--text-light);
  border-bottom-color: var(--gold);
  font-weight: 600;
}

.tab-nav a:hover:not(.active) {
  color: rgba(255, 248, 231, 0.75);
}

/* ===========================
   Invite Form
   =========================== */

.invite-section {
  margin-top: 20px;
  padding: 20px;
  background: white;
  border: 2px solid var(--wood-light);
  border-radius: 12px;
  box-shadow: 0 2px 8px var(--shadow);
  width: 100%;
  max-width: 420px;
}

.invite-section h2 {
  font-size: 1.1rem;
  color: var(--wood-brown);
  margin-bottom: 12px;
  font-family: 'Playfair Display', Georgia, serif;
}

.invite-form {
  display: flex;
  gap: 8px;
}

.invite-form input {
  flex: 1 1 0%;
  min-width: 0;
  max-width: 200px;
  padding: 10px 14px;
  border: 2px solid var(--cream-dark);
  border-radius: 8px;
  font-size: 0.95rem;
  min-height: 44px;
  font-family: inherit;
  background: var(--cream);
  color: var(--text-dark);
}

.invite-form input:focus {
  outline: none;
  border-color: var(--green-felt-light);
}

.invite-form-btn {
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--green-felt-light), var(--green-felt));
  color: var(--text-light);
  border: 2px solid var(--green-felt-dark);
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  flex-shrink: 0;
}

.invite-form-btn:hover {
  background: linear-gradient(180deg, var(--green-felt), var(--green-felt-dark));
}

.invite-list {
  margin-top: 16px;
  list-style: none;
}

.invite-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--cream-dark);
  font-size: 0.85rem;
}

.invite-list-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-link-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  opacity: 0.5;
  transition: opacity 0.15s;
}

.copy-link-btn:hover {
  opacity: 1;
}

/* ===========================
   Management Panel
   =========================== */

.management-panel {
  width: 100%;
  max-width: 420px;
}

.invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 16px;
  background: white;
  border: 2px solid var(--cream-dark);
  border-radius: 10px;
  margin-bottom: 8px;
}

.invite-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.invite-name {
  font-weight: 600;
  color: var(--text-dark);
  font-size: 0.95rem;
}

.invite-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.invite-status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.status-pending {
  background: var(--gold-light);
  color: var(--wood-dark);
}

.status-seated {
  background: var(--green-felt-light);
  color: white;
}

.status-kicked {
  background: var(--cream-dark);
  color: var(--text-muted);
}

.invite-seat {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.invite-link-row {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  margin-top: 4px;
}

.invite-link {
  font-family: monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.copy-btn {
  padding: 4px 10px;
  background: var(--cream);
  border: 1px solid var(--cream-dark);
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
}

.copy-btn:hover {
  border-color: var(--wood-light);
}

.kick-row-form {
  width: 100%;
  margin-top: 4px;
}

.kick-row-btn {
  padding: 6px 12px;
  background: white;
  border: 2px solid #c0392b;
  color: #c0392b;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.kick-row-btn:hover {
  background: #c0392b;
  color: white;
}

/* ===========================
   Seat Interaction Styles
   =========================== */

.seat-clickable {
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}

.seat-clickable:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 14px var(--shadow-strong);
  animation: seatBounce 0.3s ease;
}

.kick-btn {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #c0392b;
  color: white;
  border: none;
  font-size: 0.75rem;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px var(--shadow);
  z-index: 1;
  min-width: 26px;
  min-height: 26px;
}

.kick-btn:hover {
  background: #a93226;
}

.leave-form {
  margin-top: 2px;
}

.leave-btn {
  padding: 8px 16px;
  min-height: 44px;
  background: transparent;
  border: 1px solid var(--text-muted);
  color: var(--text-muted);
  border-radius: 6px;
  font-size: 0.7rem;
  cursor: pointer;
}

.leave-btn:hover {
  border-color: #c0392b;
  color: #c0392b;
}

.seat-form {
  display: contents;
}

/* ===========================
   Toast Notification
   =========================== */

.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: var(--green-felt);
  color: white;
  padding: 10px 24px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.3s, transform 0.3s;
  pointer-events: none;
  box-shadow: 0 4px 12px var(--shadow-strong);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===========================
   Spectator Message
   =========================== */

.guest-info-card {
  margin-top: 24px;
  padding: 20px;
  background: white;
  border: 2px solid var(--wood-light);
  border-radius: 12px;
  text-align: center;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 2px 8px var(--shadow);
}

.guest-info-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--green-felt);
  margin-bottom: 8px;
}

.guest-info-text {
  color: var(--text-dark);
  font-size: 0.9rem;
  line-height: 1.5;
}

.guest-info-hint {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-top: 10px;
  font-style: italic;
}

/* ===========================
   Empty Invites Message
   =========================== */

.empty-invites {
  text-align: center;
  color: var(--text-muted);
  padding: 32px 16px;
  font-style: italic;
}

/* ===========================
   Not Found Page
   =========================== */

.not-found {
  text-align: center;
  padding: 80px 16px;
}

.not-found h1 {
  color: var(--wood-brown);
  font-size: 1.8rem;
  margin-bottom: 12px;
}

.not-found p {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 1rem;
  line-height: 1.6;
}

.not-found .btn-create {
  max-width: 280px;
  margin: 0 auto;
}

/* ===========================
   Error Page
   =========================== */

.error-page {
  text-align: center;
  padding: 80px 16px 32px;
}

.error-page-icon {
  font-size: 3.5rem;
  margin-bottom: 16px;
  display: block;
}

.error-page h1 {
  color: var(--wood-brown);
  font-size: 1.6rem;
  margin-bottom: 12px;
}

.error-page p {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.6;
  margin-bottom: 8px;
}

.error-page .hint {
  font-style: italic;
  font-size: 0.85rem;
}

.error-page .btn-create {
  max-width: 280px;
  margin: 24px auto 0;
}

.error-page .btn-back {
  display: inline-block;
  margin-top: 16px;
  color: var(--green-felt);
  text-decoration: underline;
  font-size: 0.9rem;
}

.error-page .btn-back:hover {
  color: var(--green-felt-dark);
}

/* ===========================
   Responsive
   =========================== */

/* Small screens */
@media (max-width: 400px) {
  .container {
    padding: 16px 12px;
  }

  .table-layout {
    gap: 8px;
    grid-template-columns: 70px 1fr 70px;
    grid-template-rows: 70px 1fr 70px;
  }

  .seat {
    width: 70px;
    height: 70px;
    padding: 6px;
  }

  .table-surface {
    padding: 16px 8px;
  }

  .home-header h1 {
    font-size: 1.6rem;
  }

  .create-form {
    padding: 20px 16px;
  }

  .header-bar h1 {
    font-size: 0.95rem;
  }

  .tab-nav a {
    padding: 8px 12px;
    font-size: 0.85rem;
  }

  .home-page {
    padding: 0 12px;
  }

  .invite-form input {
    max-width: 150px;
  }

  .invite-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .invite-meta {
    width: 100%;
    justify-content: space-between;
  }
}

/* Tablet */
@media (min-width: 481px) and (max-width: 768px) {
  .container {
    max-width: 480px;
    margin: 0 auto;
  }
}

/* Desktop */
@media (min-width: 769px) {
  .container {
    max-width: 480px;
    margin: 0 auto;
    box-shadow: 0 0 40px var(--shadow);
    min-height: 100vh;
  }

  body {
    background-color: var(--cream-dark);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
