* {
  -webkit-tap-highlight-color: transparent;

  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  background: #87ceeb;
  font-family: Arial, sans-serif;
  margin: 0;
  overflow: hidden;
  padding: 0;
  touch-action: manipulation;
}

#gameContainer {
  align-items: center;
  display: flex;
  height: 100vh;
  justify-content: center;
  overflow: hidden;
  position: relative;
  width: 100vw;
}

#canvas {
  background: #87ceeb;
  display: block;
  image-rendering: -moz-crisp-edges;
  image-rendering: -webkit-crisp-edges;
  image-rendering: crisp-edges;
  position: absolute;
}

.ui-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  height: 100dvh;
  pointer-events: none;
  position: absolute;
  top: 0;
  width: 100dvw;
}

.ui-grid__corner {
  overflow: hidden;
  padding: 0.625rem;
  pointer-events: auto;
  transition: height 0.35s cubic-bezier(0.68, -0.55, 0.27, 1.5);
}

.ui-grid__corner--heading {
  backdrop-filter: blur(0.3125rem);
  background: rgba(0, 0, 0, 0.8);
  border-radius: 0.5rem;
  border: 0.0625rem solid rgba(255, 255, 255, 0.1);
  color: white;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.75rem;
}

.ui-grid__corner--container {
  cursor: pointer;
  padding: 0.5rem;
}

.ui-grid__corner--sub-heading {
  margin-bottom: 0.3125rem;
}

/* Element modifiers for sticky corners */
.ui-grid__corner--top-left {
  align-self: start;
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
}

.ui-grid__corner--top-right {
  align-self: start;
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.ui-grid__corner--bottom-left {
  align-self: end;
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
}

.ui-grid__corner--bottom-right {
  align-self: end;
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
}

#stats,
#controls,
#settings,
#inventory,
.seed-controls {
  font-size: 0.5625rem;
}

/* Stats Panel */
#stats {
  backdrop-filter: blur(0.3125rem);
  background: rgba(0, 0, 0, 0.8);
  border-radius: 0.5rem;
  border: 0.0625rem solid rgba(255, 255, 255, 0.1);
  color: white;
}

/* Settings Panel */
#settings {
  backdrop-filter: blur(0.3125rem);
  background: rgba(0, 0, 0, 0.8);
  border-radius: 0.5rem;
  border: 0.0625rem solid rgba(255, 255, 255, 0.1);
  color: white;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 2;
}

#settings .ui-grid__corner--container {
  align-items: start;
  display: flex;
  flex-direction: column;
}

#settings #resolution,
#settings select,
#settings button {
  width: 100%;
}

/* Inventory Panel */
#inventory {
  backdrop-filter: blur(0.3125rem);
  background: rgba(0, 0, 0, 0.8);
  border-radius: 0.5rem;
  border: 0.0625rem solid rgba(255, 255, 255, 0.1);
  bottom: 1.625rem;
  color: white;
}

/* Controls Panel */
#controls {
  backdrop-filter: blur(0.3125rem);
  background: rgba(0, 0, 0, 0.8);
  border-radius: 0.5rem;
  border: 0.0625rem solid rgba(255, 255, 255, 0.1);
  color: white;
}

.control-instruction {
  padding: 0.25rem 0;
}

/* Mobile Touch Controls */
#touchControls {
  bottom: 5rem;
  position: absolute;
  width: 100%;
}

.touch-btn {
  align-items: center;
  backdrop-filter: blur(0.3125rem);
  background: rgba(0, 0, 0, 0.6);
  border-radius: 50%;
  border: 0.125rem solid rgba(255, 255, 255, 0.3);
  color: white;
  cursor: pointer;
  display: inline-flex;
  font-size: 1rem;
  height: 3.5rem;
  justify-content: center;
  padding: 1.75rem;
  touch-action: manipulation;
  user-select: none;
  width: 3.5rem;
}

.touch-btn:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.95);
}

.dpad-container {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 0 1rem 1rem 0.5rem;
}

.dpad {
  display: grid;
  gap: 0.3125rem;
  grid-template-columns: 3.125rem 3.125rem 3.125rem;
  grid-template-rows: 3.125rem 3.125rem 3.125rem;
  justify-content: left;
  position: relative;
}

.dpad .up-left {
  grid-column: 1;
  grid-row: 1;
  margin-left: 0.5rem;
  margin-top: 0.5rem;
  padding: 0;
  z-index: 1;
}

.dpad .up {
  grid-column: 2;
  grid-row: 1;
  margin-left: 0.125rem;
}

.dpad .up-right {
  grid-column: 3;
  grid-row: 1;
  margin-right: 0.5rem;
  margin-top: 0.5rem;
  padding: 0;
  z-index: 1;
}

.dpad .left {
  grid-column: 1;
  grid-row: 2;
  margin-top: 0.125rem;
}

.dpad .right {
  grid-column: 3;
  grid-row: 2;
  margin-top: 0.125rem;
}

.dpad .down-left {
  grid-column: 1;
  grid-row: 3;
  margin-bottom: 0.5rem;
  margin-left: 0.5rem;
  padding: 0;
  z-index: 1;
}

.dpad .down {
  grid-column: 2;
  grid-row: 3;
  margin-left: 0.125rem;
}

.dpad .down-right {
  grid-column: 3;
  grid-row: 3;
  margin-bottom: 0.5rem;
  margin-right: 0.5rem;
  padding: 0;
  z-index: 1;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  justify-content: end;
}

/* Button Styles */
button,
select {
  background: #4caf50;
  border-radius: 0.25rem;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 0.625rem;
  margin: 0.125rem;
  padding: 0.375rem 0.75rem;
  transition: background 0.2s;
}

button:hover,
button:focus {
  background: #45a049;
  outline: none;
}

button:active {
  transform: scale(0.95);
}

select {
  background: #333;
  border: 0.0625rem solid #555;
}

select:focus {
  outline: 0.125rem solid #4caf50;
}

.seed-btn {
  background: #8b4513;
  font-size: 0.5625rem;
  margin: 0.125rem;
  padding: 0.25rem 0.5rem;
}

.seed-btn:hover {
  background: #654321;
}

.seed-btn.selected {
  background: #ff6b35;
  border: 0.125rem solid #fff;
}

#resolution {
  display: inline;
  margin-bottom: 0.5rem;
}

/* Desktop Resolution Classes */
.resolution-400 #canvas {
  border: 0.125rem solid #333;
  height: 25rem;
  margin: auto;
  width: 25rem;
}

.resolution-800 #canvas {
  border: 0.125rem solid #333;
  height: 50rem;
  margin: auto;
  width: 50rem;
}

.desktop-resolution #gameContainer {
  background: #2c3e50;
}

.seed-controls {
  background: rgba(0, 0, 0, 0.7);
  border-radius: 0.3125rem;
  bottom: 0;
  color: white;
  margin: 0.625rem 0;
  padding: 0.625rem;
  position: absolute;
  z-index: 2;
}

.seed-controls__actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
}

.seed-controls h4 {
  color: white;
  margin: 0 0 0.625rem 0;
}

.seed-controls input {
  font-size: 0.75rem;
  margin-left: 0.3125rem;
  padding: 0.125rem 0.3125rem;
  width: 5rem;
  font-size: 0.5rem;
}

.seed-controls input:focus {
  outline: 0.125rem solid #4a90e2;
}

.tile-btn {
  background: white;
  border-radius: 0.125rem;
  border: 0.0625rem solid #ccc;
  cursor: pointer;
  font-size: 0.625rem;
  padding: 0.25rem 0.375rem;
  transition: all 0.2s;
}

.tile-btn:hover {
  border-color: #666;
  transform: scale(1.05);
}

.tile-btn.selected {
  background: #e6f3ff;
  border-color: #0066cc;
  border-width: 0.125rem;
  font-weight: bold;
}

#mapEditor {
  border-top: 0.0625rem solid #ccc;
  margin-top: 0.625rem;
  padding-top: 0.625rem;
}

#mapEditorControls {
  margin-top: 0.3125rem;
}

#mapEditorControls > div {
  margin-bottom: 0.5rem;
}

#brushSizeSelect {
  margin-left: 0.3125rem;
  padding: 0.125rem;
}

#generateWithSeed {
  background: #4a90e2;
}

#randomSeed {
  background: #f39c12;
}

#copySeed {
  background: #27ae60;
}

.seed-controls button {
  border-radius: 0.1875rem;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0.3125rem 0.625rem;
}

.seed-controls button:hover {
  opacity: 0.8;
  transform: translateY(-0.0625rem);
}

.seed-controls button:active {
  transform: translateY(0);
}

.current-seed {
  color: #bbb;
  font-size: 0.6875rem;
  margin-top: 0.5rem;
}

/* Mobile Responsive */
@media (min-width: 30rem) {
  .ui-grid__corner--heading {
    font-size: 1rem;
  }

  #stats,
  #controls,
  #settings,
  #inventory,
  .seed-controls {
    font-size: 0.725rem;
  }

  .touch-btn {
    font-size: 0.75rem;
  }

  .seed-controls {
    font-size: 0.6875rem;
  }

  .seed-controls button {
    font-size: 0.6875rem;
    padding: 0.25rem 0.5rem;
  }

  .seed-controls input {
    width: 3.75rem;
  }
}

@media (min-width: 48rem) {
  .ui-grid__corner--heading {
    font-size: 1.25rem;
  }

  #stats,
  #controls,
  #settings,
  #inventory,
  .seed-controls {
    font-size: 1.25rem;
  }

  .touch-btn {
    font-size: 0.875rem;
  }
}
